Unable to access vline.Message object with postMessage() - javascript

While implementing the vLine API, I came up with a problem. When using the postMessage() method of the vline.Channel class, the message was successfully received by the target user, but the the success callback of vline.Promise object did not return a valid vline.Message object. At least I don't have acess to some of the vline.Message methods, like getChannel() or getCreationTime().
Code:
$channel.postMessage(textMessage)
.done(function (message) {
console.log("Message sending successfull || Message sent to " + message.getChannel().getDisplayName() + " at " + message.getCreationTime());
},
this)
.fail(function (err) {
console.log("Message sending failed || Error Type: " + err.type + " || Error Message: " + err.message);
},
this);
Result (console log):
Message sending failed || Error Type: undefined || Error Message: Object #<Object> has no method 'getChannel'
Is this result of a API change that has not been yet referenced on the vLine Developer site or is there an error on the code?

This was a bug on our end; sorry about that. It should now be fixed.

Related

Window.onerror doesn't return info about error

I'm trying to create a custom error handler. I've got the following code to intercept the errors:
window.onerror = function (msg, url, lineNo, columnNo, error) {
console.log("msg: " + msg + "url: " + url + "lineNo: " + lineNo + "columnNo: " + columnNo);
}
Then later in the code I'm trying to console.log a variable that doesn't exist (in order to trigger the error). In the console I'm getting the custom:
msg: Script error.url: lineNo: 0columnNo: 0
And below that the default:
myjsfile.js:517 Uncaught ReferenceError: xyz is not defined(…)
How can I access this information - filename, line number, error message - and add it to my custom message? Thank you!
You really should use try-catch
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/try...catch
create object with all your variables in try and throw it
try {
throw your_obj;
}
and
catch(e)
{
console.log(e); //will print whatever you made "your_obj" to be
}

Parse.com JavaScript query error handling does not work

I'm playing around with the Parse backend and NodeJS but I have a problem right now and I am not able to figure it out. I have a get request like this.
app.get("/movie", function (req, res) {
var Review = Parse.Object.extend("Review");
var query = new Parse.Query(Review);
var movie = req.query.movie;
query.equalTo("movie", movie);
query.first({
success: function (movie) {
console.log("Success");
},
error: function (error) {
console.log("Error: " + error.code + " " + error.message);
}
});});
This works fine but the error handling kinda doesn't. If, for example, I change
query.equalTo("movie", movie);
to query.equalTo("movie", "xyz");
or query.equalTo("abc", "xyz");
which does not exist in my table, I'm still getting the success statement. And yes, I have restarted the server every time.
Update
I tried the same query using the iOS SDK(Swift) and here I get into the error case. I always get the same error though, which shouldn't be, but at least I get an error while in the JS sample I always get into the success case.
I believe query.first() will not error if it does not find a "first" object. You can check for (movie == null) on the success return.
Update:
Try writing it this way:
app.get("/movie", function (req, res) {
var movie = req.query.movie;
var query = new Parse.Query("Review");
query.equalTo("movie", movie);
query.first().then(function (movie) {
// Success
console.log("Success");
}, function (error) {
// Error
console.log("Error: " + error.code + " " + error.message);
});
});
query.find() always success even if there is no match data in your table/collections
Let's try it
query.find().then(function (movies) {
if(movies.length > 0){
console.log("success");
}else{
console.log("query success but no data found");
}
}, function (error) {
// Error
console.log("Error: " + error.code + " " + error.message);
});

Parse Javascript - Adding user error

I created a factory in angularJS to store data to Parse User object. Every time I click to process the details and open an account for the user, it shows the following error in console:
Failed to load resource: https://api.parse.com/1/users the server
responded with a status of 400 (Bad Request)
I checked if the service parameter is valid with attributes content, and yes it has content (not empty). This is the service body:
.factory('CreateUserService', function() {
return {
createAccount: function(user) {
console.log("Service User: " + user.name);
var parseUser = new Parse.User();
parseUser.set("username", user.username);
parseUser.set("email", user.username);
parseUser.set("name", user.username);
parseUser.set("password", user.username);
parseUser.set("mobile", user.username);
/*Attempt to create user in DB*/
parseUser.signUp(null, {
success: function(parseUser) {
// Hooray! Let them use the app now.
//alert("success!");
return 1;
},
error: function(parseUser, error) {
// Show the error message somewhere and let the user try again.
//alert("Error: " + error.code + " " + error.message);
return error;
}
});
}
}
});
I added the Parse CDN in the index.html of my application with:
<script src="http://www.parsecdn.com/js/parse-1.6.7.min.js"></script>
Update: In Parse API Guide, this is the body of the signup:
user.signUp(null, {
success: function(user) {
// Hooray! Let them use the app now.
},
error: function(user, error) {
// Show the error message somewhere and let the user try again.
alert("Error: " + error.code + " " + error.message);
}
});
The user object in Parse (I review through the browser) is not showing any changes to the rows number hence user not added. Any idea what is going wrong?
Thanks
Update: When I deleted the existing empty user object in Parse and ran the code, it worked and created a user Object with all columns specified in the code. Then if I try to add another user, I get a POST error. There must be a way around this since signup method by parse surely considered adding multiple users to the User object.

window.onerror and [object Event]

I have some errorlogging code on my website that saves Javascript errors to a file so later i can look to se if there is problems with my code in some browsers.
Sometimes i get a error message like message:[object Event] url:undefined line:undefined so i dont know where the error accures.
How do i get more info from message when it is [object Event] so i can know what file and line number the error is from.
window.onerror = error;
function error(message, url, line) {
// sometimes message is [object Event]
}
I am thinks something like this.
window.onerror = error;
function error(message, url, line) {
// sometimes message is [object Event]
if (typeof message === 'object') {
message = message
+ ' + '
+ message.url
+ ' + '
+ message.lineno;
}
}
Trying this but i get Uncaught TypeError: Object # has no method 'serialize'
if (typeof message === 'object') {
message = JSON.serialize(message);
}
With JSON.stringify(message) i get Uncaught TypeError: Converting circular structure to JSON
if (typeof message === 'object') {
message = JSON.stringify(message);
}
In the case where you get something like [someting Something] in JS, it usually means that it is an object. You can do a console.log(message) and inspect the contents of the object. It would look like
{
somethingHere : 'data',
anotherHere : 'more data'
}
To access them, you can do it in the dot notation:
theObject.somethingHere //data
In your case, that would be like this, where something is a key from the object.
message.something
On which browser or browsers are you seeing this [Event object] message occurring? One possible way to inspect the contents of the object is:
var messageString = '';
for (var x in message) {
if (messageString) messageString += ', ';
messageString += x + ': ' + message[x];
}
message = '{' + messageString + '}';
If you can give any kind of reproducible test case for this onerror message, including browser versions on which is happens, that would help a lot.

$.getJSON parsererror trying to call API

I'm trying to use the Clipped API (http://clipped.me/api.html) that returns JSON but am running into some trouble. I'm using getJSON, and in Chrome's JS console I get these error messages:
Resource interpreted as Script but transferred with MIME type text/html: "http://clipped.me/algorithm/clippedapi.php?url=callback=jQuery1910859611126…emo-day-2013-still-looking-for-the-next-airbnb-or-dropbox/&_=1364420105379".
Uncaught SyntaxError: Unexpected identifier
Request Failed: parsererror, Error: jQuery19108596111265942454_1364420105378 was not called
And here's my JS:
var clippedAPI = "http://clipped.me/algorithm/clippedapi.php?url=[URL]callback=?";
$.getJSON(clippedAPI, "http://pandodaily.com/2013/03/26/y-combinator-demo-day-2013-still-looking-for-the-next-airbnb-or-dropbox/" ).done(function(json) {
console.log("JSON Data: " + json.title );
}).fail(function(jqxhr, textStatus, error){
var err = textStatus + ', ' + error;
console.log("Request Failed: " + err);
});
This is my first time trying to make something with an API or JSON at all, so I'm really not sure what to do here. I've tried Googling around but can't find anything. The data that I'm actually sending is getting cut off by this jQuery notice that appears when I add callback=?
Your parameter will not simply "guess" what the [URL] param is. Try this:
var clippedAPI = "http://clipped.me/algorithm/clippedapi.php";
$.ajax({
url: clippedAPI,
type: "GET",
dataType: "JSONP",
data: {
url: "http://pandodaily.com/2013/03/26/y-combinator-demo-day-2013-still-looking-for- the-next-airbnb-or-dropbox/"}
}).done(function(json) {
console.log("JSON Data: " + json.title );
}).fail(function(jqxhr, textStatus, error){
var err = textStatus + ', ' + error;
console.log("Request Failed: " + err);
});
Even this fails, however, as your API endpoint does not seem to understand/support JSONP and does not provide a Access-Control-Allow-Origin header. You therefore have two choices:
You can reverse-proxy the API locally to get around the cross-domain issue and go through standard JSON
You can...ehm... get a better API? Lodge a ticket with the devs to get it sorted.

Categories

Resources