Create an empty promise that just fulfills?

Javascriptnode.js

Javascript Problem Overview


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

Javascript Solutions


Solution 1 - Javascript

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionHimmatorsView Question on Stackoverflow
Solution 1 - Javascriptguest271314View Answer on Stackoverflow