Documentation
¶
Overview ¶
Package httperror provides common error handling, particularly around golang errors and responses
Index ¶
Constants ¶
const ( // DefaultStatus is the response status code used when the error's code // is less than http.StatusBadRequest (400), i.e. when the code is not // an HTTP error code. DefaultStatus = http.StatusInternalServerError )
Variables ¶
This section is empty.
Functions ¶
func Write ¶
func Write(response http.ResponseWriter, err error) (int, error)
Write handles writing the given error to the response, taking care of the response status and any output headers. This function can be used with errors other than HTTP errors. It will provide default behavior in that case.
If a status other than DefaultStatus is desired, use WriteMessage(response, err.Error(), DesiredStatus, nil) instead of this function.
func WriteMessage ¶
func WriteMessage(response http.ResponseWriter, message string, status int, header http.Header) (int, error)
WriteMessage handles writing full error message information out to a response. This function avoids the overhead of creating a full blown HTTP error object.
If status is not an HTTP error code, DefaultStatus is used. The header is optional, and can be nil.
Types ¶
type Interface ¶
Interface represents an HTTP-specific error with additional metadata for the response.