-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
pages respond with 500 status if missing action #111
Comments
Graham42
changed the title
Support non-500 status for intentionally not supported methods
pages respond with 500 status if missing action
May 4, 2021
You raise a valid concern, as it differs from the way a classical HTTP server would handle this. I'm wondering what way the fix would go:
|
we should change it to 405, and then consider some generic way to handle this in the future. |
2 tasks
Fixed in #2342 |
1 task
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For the home page of my site I only want to support
GET
requests, but if a bot comes along and does a drive-byPOST
request, then I end up with a500
status response being returned and a stacktrace in my logs. This adds noise and false positives to monitoring which makes it harder to detect real issues. The500
status code should be reserved for unexpected errors, and in the case of aPOST
request to/
I intend to not support that method.For the first approach I tried adding an action function the returned a simple response with a
405
(Method Not Allowed) statusBut when I make the
POST
request, the result is a500
internal server error and the log error is:This makes lots of sense for a form, but for a page where I expect to never recieve a
POST
,PUT
, etc I don't think it applies.For my next approach I tried what feels like a bit of a 🐒 🔧 monkey patch as it uses remix internals. In the⚠️ This code ends up always returning
server/index.js
file I've set up a handler to wrap the remix handler which checks if there's a route match (I think I did this wrong) and if there is, checks if there's an action for the route. If there's no action it then sends a405
response. Otherwise it falls back to the remix handler.405
s though, and not404
s because it doesn't detect route matching correctly.server/index.js
:Maybe it would be helpful to have an option for a default action handler?
To restate my goal here: I would like to not see responses with a status code of
500
unless there's a real error in my code that I need to investigate. This is important for monitoring the health of a site.Thanks for your time reading this post!
The text was updated successfully, but these errors were encountered: