PatrickDotStar
PatrickDotStar

Reputation: 1794

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.

Upvotes: 1

Views: 245

Answers (2)

ittus
ittus

Reputation: 22403

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);

});

Upvotes: 1

BuffMcBigHuge
BuffMcBigHuge

Reputation: 626

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);

    });
});

Upvotes: 1

Related Questions