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

Implement shorthand error handling #61

Open
jnichols-git opened this issue Apr 29, 2023 · 2 comments
Open

Implement shorthand error handling #61

jnichols-git opened this issue Apr 29, 2023 · 2 comments
Assignees
Labels
minor Non-breaking overhauls, new API functions

Comments

@jnichols-git
Copy link
Owner

jnichols-git commented Apr 29, 2023

RFC 7807 defines a standard response format for HTTP handling problems. Error handling in Go has always been a bit verbose, but HTTP introduces the additional step of constructing and writing a response each time, which can be very frustrating if you want to have an error that isn't 500 Internal Server Error. I would like to implement a standard ProblemResponse that takes in a ResponseWriter and fields related to 7807 (type string, title string, status code, detail string, instance string) and writes a formatted response with content type `application/problem+json. This function/type should validate that the inputs are OK according to spec (so type and instance must be URIs, etc).

Notably, this should not write a problem on panics--exposing internal errors can be a serious security issue, and the decision to use RFC 7807 or not should be a conscious one made during regular operation.

Since 7807 is a proposal, I would also like to implement an ErrorResponse that just takes in a code and an error instead of the problem fields.

@jnichols-git jnichols-git added help wanted Extra attention is needed minor Non-breaking overhauls, new API functions labels Apr 29, 2023
@jnichols-git jnichols-git changed the title Implement RFC 7807 error handling Implement shorthand error handling Apr 29, 2023
@SuneelFreimuth
Copy link
Contributor

Down to take this.

@jnichols-git jnichols-git removed the help wanted Extra attention is needed label May 8, 2023
@jnichols-git
Copy link
Owner Author

Assigned!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
minor Non-breaking overhauls, new API functions
Projects
None yet
Development

No branches or pull requests

2 participants