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

Forward errors along to error handling middlewares #11

Merged

Conversation

arjansingh
Copy link
Contributor

@arjansingh arjansingh commented Aug 24, 2016

This would address issues discussed in: ember-fastboot/fastboot#76

Relevant express documentation: https://expressjs.com/en/guide/error-handling.html

@arjansingh
Copy link
Contributor Author

Looks like this is an alternative to #4.

@arjansingh
Copy link
Contributor Author

Note to self, write test to check what happens if we have no error handling middleware.

@arjansingh
Copy link
Contributor Author

@tomdale Updated test cases to include testing error propagation when there is no custom error handling middleware. Can you double check the cases for accuracy?

I'm happy to add any more that you can think of as well.

@danmcclain
Copy link
Member

danmcclain commented Aug 31, 2016

LGTM 👍 I take that back, I've added a comment

res.status(result.statusCode);
res.send(html);
})
.catch(error => {
console.log(error.stack);
log(500, error.stack);
next(error);
res.sendStatus(500);
Copy link
Member

Choose a reason for hiding this comment

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

Should we res.status here instead, so that middleware can alter the response, instead of being forced to deal with sendStatus

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yup. will do.

Copy link
Member

Choose a reason for hiding this comment

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

next should be called last

@arjansingh
Copy link
Contributor Author

@danmcclain @tomdale Look it over one more time?

res.sendStatus(500);
}
if (error.name !== "UnrecognizedURLError") {
res.status(500);
Copy link
Member

Choose a reason for hiding this comment

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

Do we even need to do this? Or would the default handler do this?

Copy link
Contributor Author

@arjansingh arjansingh Sep 3, 2016

Choose a reason for hiding this comment

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

I think we should set 500 because that accurately reflects the state of the request when it leaves the FastBoot middleware.

If post-FastBoot middleware wants to change the status code and attempt recovery it can. But that doesn't change the fact that our middleware resulted in an internal server error (i.e., a 500).

Copy link
Contributor

Choose a reason for hiding this comment

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

@arjansingh That rationale sounds reasonable to me.

@arjansingh
Copy link
Contributor Author

arjansingh commented Sep 8, 2016

@danmcclain @tomdale Bueller? 😁

@danmcclain danmcclain merged commit db8fdbc into ember-fastboot:master Sep 13, 2016
@danmcclain
Copy link
Member

Thanks @arjansingh 👏

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.

3 participants