Himmators Himmators - 3 months ago 10x
Node.js Question

Create an empty promise that just fulfills?

I have a wrapper that catches the last result of a promise, formats it and outputs the data:

req.resolve = (promise) => {
return promise.then(() => {
}).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

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


Promise constructor requires executor function as parameter. Substitute Promise.resolve() for new Promise()