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

fix(rest): improves error handling for express middleware #4532

Merged
merged 1 commit into from
Feb 13, 2020

Conversation

raymondfeng
Copy link
Contributor

@raymondfeng raymondfeng commented Jan 28, 2020

Fixes #4530

Checklist

👉 Read and sign the CLA (Contributor License Agreement) 👈

  • npm test passes on your machine
  • New tests added or existing tests modified to cover all changes
  • Code conforms with the style guide
  • API Documentation in code was updated
  • Documentation in /docs/site was updated
  • Affected artifact templates in packages/cli were updated
  • Affected example projects in examples/* were updated

👉 Check out how to submit a PR 👈

Copy link
Member

@bajtos bajtos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for opening a PR to fix the crash. I have different opinions on how to fix the problem, please see my comments below.

packages/rest/src/rest.server.ts Show resolved Hide resolved
packages/rest/src/rest.server.ts Outdated Show resolved Hide resolved
@raymondfeng
Copy link
Contributor Author

@bajtos PTAL.

Copy link
Member

@bajtos bajtos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new proposal looks much better now 👍

Can you please clean up the code a bit per my comment below?

I am also a bit concerned that by invoking the new error handler also for errors leaked by the sequence, we may end up with calling reject two times:

  1. First, we call reject from the sequence. Something unexpected happens and an error is thrown.
  2. Then we call reject again from the last-resort error handler.

Maybe this is not a problem? IDK.

packages/rest/src/rest.server.ts Show resolved Hide resolved
@raymondfeng
Copy link
Contributor Author

I am also a bit concerned that by invoking the new error handler also for errors leaked by the sequence, we may end up with calling reject two times:
First, we call reject from the sequence. Something unexpected happens and an error is thrown.
Then we call reject again from the last-resort error handler.

Good question. I think it's a rare edge case and probably not too bad to call it twice.

@raymondfeng raymondfeng merged commit 02d0c91 into master Feb 13, 2020
@raymondfeng raymondfeng deleted the fix-4530 branch February 13, 2020 08:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CORS origin custom function throw and crash the app
4 participants