Parse.Promise cannot catch error

I am working on a project that uses Parse.com npm package in NodeJS and here is the problem:

  Parse.Promise.as(true).then(function() {
    throw new Error('here is an error');
  }).then(function(done) {
    console.log('done', done);
  }, function(err) {
    console.log('err', err);
  });
      

Run codeHide result


This code should record "err" and "error here". But this is not the case. Just an error immediately came out:

Error: here is an error
    at module.exports.app.get.res.title.js.css.route.noChat (/Users/Nemo/dev/workspace/snapfitWeb/lib/event.js:10:11)
    at wrappedResolvedCallback (/Users/Nemo/dev/workspace/snapfitWeb/node_modules/parse/build/parse-latest.js:4082:40)
    at /Users/Nemo/dev/workspace/snapfitWeb/node_modules/parse/build/parse-latest.js:4144:35
    at runLater (/Users/Nemo/dev/workspace/snapfitWeb/node_modules/parse/build/parse-latest.js:4127:14)
    at _.extend.then (/Users/Nemo/dev/workspace/snapfitWeb/node_modules/parse/build/parse-latest.js:4143:9)
    at module.exports.app.get.res.title.js.css.route.noChat (/Users/Nemo/dev/workspace/snapfitWeb/lib/event.js:9:26)
    at Object.<anonymous> (/Users/Nemo/dev/workspace/snapfitWeb/lib/event.js:17:3)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
      

Run codeHide result


Environment: Node v0.10.38 express@4.12.3 parse@1.4.2

+3


source to share


1 answer


To pass the error to the error callback, return the rejected promise, for example:



Parse.Promise.as(true).then(function() {
    return Parse.Promise.error("here is an error");
}).then(function(done) {
    console.log('done', done);
}, function(err) {
    console.log('err', err);
});

      

+3


source







All Articles