1

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.

2 Answers 2

1

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

    });
});
Sign up to request clarification or add additional context in comments.

3 Comments

Still the same result :(
This is kinda weird. If I change 'var query = new Parse.Query("Review");' to 'var query = new Parse.Query("XYZ");' I still get the 'Success' log
You can also force an error by doing: If (!movie) { return Parse.Promise.error();}
1

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

});

1 Comment

Thanks for your reply. I know that this works but this is not in the sense of error handling. Parse offers some Error codes like 'ObjectNotFound', 'InvalidQuery' and 'InvalidClassName'. I can check these in the error case using an if statement. And I just don't understand, why my query constraint does not work. I mean, if I set the constraint like I did in my post where this data doesn't even exist, I should not get into the success case but I do every time.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.