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

Wrong http status code (500) returned instead of 404 or any response thrown from a loader. #145

Closed
zvin opened this issue Jan 17, 2023 · 9 comments

Comments

@zvin
Copy link

zvin commented Jan 17, 2023

Have you experienced this bug with the latest version of the template?

yes

Steps to Reproduce

  • npx create-remix@latest;
  • select the blues template, follow the suggested steps;
  • go to any page that doesn't exist, http://0.0.0.0:3000/no-such-page for example
  • see that the returned status is 500 instead of 404

The same issue happens if you throw a json response in a loader: throw json("Unauthorized", { status: 403 });, a 500 status code will be returned to the browser.

It seems like this started happening when updating remix from 1.9.0 to 1.10.0.
The issue does not happen when using remix serve instead of express.
I don't know if the issue comes from the template server.ts file or from the combination of @remix-run/react and @remix-run/express

Expected Behavior

A 404 http status code should be returned.
Capture d’écran du 2023-01-17 20-02-01

Actual Behavior

A 500 http status code is returned.
Capture d’écran du 2023-01-17 19-45-26

@zvin
Copy link
Author

zvin commented Jan 17, 2023

Minimal reproduction here: https://stackblitz.com/edit/node-zxrwpd

@zvin
Copy link
Author

zvin commented Jan 18, 2023

One thing that solves the issue is to remove the eslint --bundle flag here

@machour
Copy link
Collaborator

machour commented Jan 18, 2023

This is an intended behavior in production, see Matt's answer here: remix-run/remix#5115 (comment)

@zvin
Copy link
Author

zvin commented Jan 18, 2023

I don't think that this is the same issue.
It also happens in development.
And even in production a page that doesn't exist should send a 404, not a 500.
The behavior differs from previous remix versions and from running it with remix serve.

@zvin
Copy link
Author

zvin commented Jan 18, 2023

The issue does not happen when not using eslint's --bundle flag or running server.ts with ts-node directly.

@brophdawg11
Copy link
Contributor

This looks like an issue with the bundling approach causing multiple disparate ErrorResponse classes to exist and this causing internal instanceof ErrorResponse checks to fail. We'll need to change those checks to avoid using instanceof for bundling approaches like this and instead use prop detection

@brophdawg11
Copy link
Contributor

The above merged PR will go in the next react router release, either 6.7.1 or 6.8.0 depending on what is in it. Then Remix will pick that up in it's next release.

@zvin
Copy link
Author

zvin commented Jan 19, 2023

Thanks for the quick fix!

@brophdawg11
Copy link
Contributor

This should be fixed with Remix 1.12.0 which should be out in the next hour or two

@mcansh mcansh closed this as completed Apr 13, 2023
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

No branches or pull requests

4 participants