I have a wrapper that catches the last result of a promise, formats it and outputs the data:
req.resolve = (promise) => { return promise.then(() => { res.json(req.user); }).catch(Sequelize.ValidationError, err => { // respond with validation errors return res.status(422).send(err.errors); }).catch(err => { // every other error return res.status(400).send({ message: err.message }); }); };
In one view, I don't have a promise, all that happens is that the auth-function triggers adds req.user and triggers done()
.
I tried adding a promise like this, but it doesn't get resolved.
app.get('/user/me', auth, (req, res, next) => { req.resolve(new Promise()); });
Empty-promise definition (idiomatic) A promise that is either not going to be carried out, worthless or meaningless. noun.
An "empty promise" is another way of saying "a lie" in english.. so having an instantly resolved promise is better, just from a language standpoint ;) Promise. resolve() worked for me! new Promise now requires a parameter, use Promise.
To return an empty promise with JavaScript, we can use an async function or call Promise. resolve . to create 2 functions that returns empty promises. p1 is an async function, so it's a function that always returns a promise.
No. It is not safe to resolve/reject promise multiple times. It is basically a bug, that is hard to catch, becasue it can be not always reproducible.
Promise
constructor requires executor function as parameter. Substitute Promise.resolve()
for new Promise()
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