Skip to content

Conversation

@ale-grosselle
Copy link

Description

When using this router with Next.js, which relies on the statusCode property (and not status), errors incorrectly default to a 500 status because Next.js does not read the status property.

In Express 4.x, both status and statusCode were set on error objects. However, in this version, only status is set. This causes compatibility issues with Next.js, resulting in incorrect HTTP status codes being returned.

This fix ensures that the statusCode property is also set on error objects in layer.js, restoring compatibility with Next.js and preventing erroneous 500 responses.

Copy link
Member

@bjohansebas bjohansebas left a comment

Choose a reason for hiding this comment

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

Hi, it’s necessary to add or modify the tests to verify the behavior you want.

Edit: I haven’t reviewed the PR in depth yet, I’ll do it later. But it would be good if you could add tests.

@ale-grosselle
Copy link
Author

Hi @bjohansebas, you're right – I'll implement a test for it.

Just to share some context: I was simply reporting how it was implemented in Express 4.x, and with that implementation, there were no unexpected 500 errors when used with Next.js:
https://github.com/expressjs/express/blob/4.21.2/lib/router/layer.js#L176

@ale-grosselle
Copy link
Author

Hi @bjohansebas test added

@ale-grosselle
Copy link
Author

Hello @bjohansebas any updates?
Thanks, Ale

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