I'm working on a project which use Parse.com npm package in NodeJS, and here is a 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);
});
This code should logs "err" and "here is an error". But it's not. Just thrown the error immediately like this:
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)
Environment: Node v0.10.38 [email protected] [email protected]
To convey an error to the error callback, return a rejected promise, like this:
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);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With