Parse .then method and chaining | Syntax eludes me

2019-09-16 22:13发布

问题:

Previous post: Parse .then method and chaining | Syntax eludes me

My original question was well answered by Nath. However I'm currently experiencing a TypeError which I am yet unable to resolve.

TypeError message:

TypeError: e is undefined


...arse.Object");return{__type:"Pointer",className:this.className,obj

My current code (updated 2014-08-14 18:44):

function harness(){
    try{
        console.log("harness function");

        Parse.initialize("*key1*", "*key2*"); //Note: I do have the keys set properly

        var query = new Parse.Query("Users");

        var userEmail = app.getValue("txtEmail");   
        console.log("userEmail: "+userEmail); 
        //Note: Using Application Craft hence the use of 'app.getValue' and other custom JS functions

        query.equalTo("email", userEmail);  console.log(query);

        query.find().then(
            function(results) {    
                    console.log("Within the Then!");
                    console.log(results); 
                    return query.find();
                },                
                function(error){
                    console.log("Could be an error"+error);
                    return;
                }

        );

        console.log("END harness function");
    }
    catch(err){
        errorHandler("harness ERROR", err.message);
        console.log(err);
    }
}

Having read various forum posts I've investigated the stack trace and given the variable 'e' am fairly certain it's the ParseCDN I'm not calling correctly. I suspect my inexperience with returning promises is the source of the issue (tried to follow Nath's advice). The commented code block at the top was one of my variations of a promise to be returned; having read through the Parse API Docs it seemed that .then inherently returned a promise anyway so 'settled' on simply returning my results, and then the queryObject again (per their samples).

The DOM upon error is interesting because it lists find(e) as a method, yet not then(). Not sure if I'm referring to an outdated js library perhaps (don't think so).

If anyone can assist, or potentially expand upon Nath's work so far (copy below) I would greatly appreciate it.

Many thanks -James

Amended code snippet from Nath

query.find().then(function(result){
  doSomethingAsync(); //must return a promise for chaining to work!
}).then(null,function(error){
  // an alternative way to handle errors
  //handles errors for all chained promises.
})