Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling promises at router layer #3610

Closed
wants to merge 2 commits into from
Closed

Handling promises at router layer #3610

wants to merge 2 commits into from

Conversation

davidbayo10
Copy link

No description provided.

@dougwilson
Copy link
Contributor

Hi @davidbayo10 thanks for the effort you put into this PR. You can find many, many discussions for making this exact change, including existing PRs which this duplicates. Unfortunately this cannot be added to Express 4, due to people already having existing code that is returning a promise and not expecting the rejection to call next, resulting in multiple calls to next occurring in existing code bases.

You can follow the most recent discussion on this here: #3604

If you think there is a better way to add promises than the existing PRs, you're welcome to make another and outline the differences from the existing proposals, but the PR would need to be made against the 5.0 branch (not master) 👍

@davidbayo10
Copy link
Author

Hi @dougwilson, my main target on that development It is because an async function (async/await), which It is repeated in all controllers, looks like that:

async function (req, res, next) {
  try {
    const result = await asyncFunction();
    res.send(result);
  } catch (err) {
    next(err);
  }
}

I think this looks some better:

async function (req, res, next) {
  const result = await asyncFunction();
  res.send(result);
}

I this case, Layer class is responsible of catch and propagate a possible error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants