Saturday, May 25, 2024
 Popular · Latest · Hot · Upcoming
145
rated 0 times [  147] [ 2]  / answers: 1 / hits: 132866  / 8 Years ago, tue, june 28, 2016, 12:00:00

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());
});

More From » node.js

 Answers
16

The Promise constructor requires an executor function in its parameter.


If you just need a dummy promise, then you can use Promise.resolve() instead of new Promise().


[#61598] Sunday, June 26, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
elliem

Total Points: 415
Total Questions: 117
Total Answers: 94

Location: American Samoa
Member since Fri, Aug 26, 2022
2 Years ago
;