I'm new to Promise, so I was trying out Bluebird's Promise APIs. I have the following method that returns a Promise.try()
CheckDb - Promise Method
const Prom = require("bluebird")
..........
..........
let checkDb = () => {
return Prom.try(() => {
SomePromiseMethod().then(result => {
if (//some condition) {
let resp = {
res: result,
somethingelse : somethingelse
}
return Prom.resolve(resp)
}
else
return Prom.reject(new Error("some reason"));
}, err => {
return Prom.reject(err);
})
.catch(err => {
return Prom.reject(err);
});
});
}
SomeTask - Method calling the promise method
exports.someTask = () => {
checkDb().then(resolved => {
console.log(resolved) // coming undefined
},
rejected => {
console.error(rejected);
})
.catch(err => {console.error(err)});
}
The problem here is that the resolved component of the then method of the Promise function is returning undefined.
return Prom.try({ SomePromiseMethod().thenis a syntax error - baao.catch(err => { return Prom.reject(err); });is just the same as not having the catch at all ... similarly with the onrejected handler above it - there's no reason for it at all - Jaromanda X