-
Notifications
You must be signed in to change notification settings - Fork 18k
net/http: Custom Error handlers #10123
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
Comments
It's hard to get excited about this. Something like this?
Seems a bit gross TBH. I don't know that we want to add yet another hook. |
It so easy to write your own functions. |
@rsc how would one write an error handler for the not found case and use that in the built-in file server instead of the |
Give |
@bradfitz that's an interesting take I had not thought of. It should work. My issue with it is that it's not a good separation of concerns. It's a hack to work around this limitation. Something that's responsible with content now needs to look for certain types of responses and override the output to something custom. It would be nice to have a clean solution. |
In the
http
packageError
displays just an error message. When building a web application you will often want to have style error pages matching the site or application. In order to get this with Go you need to implement your ownError
handling along with any code that calls it.For example, if you want custom error pages (including 404 not found pages) and want to serve files you need to bypass the built in file server and re-implement much of it to change the error page handling.
It would be far simpler to allow the
Error
to provide a default but be capable of being replaced.The text was updated successfully, but these errors were encountered: