{"modulePath":"github.com/hellofresh/janus","version":"v0.0.0-20230925145208-ce8de8183c67","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package errors\n\nPackage errors provides a nice way of handling http errors\n\nExamples: To create an error:\n\n\terr := errors.New(http.StatusBadRequest, \"Something went wrong\")\n\n## Variables\n\n```go\nvar (\n\t// ErrRouteNotFound happens when no route was matched\n\tErrRouteNotFound = New(http.StatusNotFound, \"no API found with those values\")\n\t// ErrInvalidID represents an invalid identifier\n\tErrInvalidID = New(http.StatusBadRequest, \"please provide a valid ID\")\n)\n```\n\n## Functions\n\n```go\nfunc Handler(w http.ResponseWriter, r *http.Request, err interface{})\n```\nHandler marshals an error to JSON, automatically escaping HTML and setting the Content-Type as application/json.\n\n```go\nfunc NotFound(w http.ResponseWriter, r *http.Request)\n```\nNotFound handler is called when no route is matched\n\n```go\nfunc RecoveryHandler(w http.ResponseWriter, r *http.Request, err interface{})\n```\nRecoveryHandler handler is used when a panic happens\n\n## Types\n\n```go\ntype Error struct {\n\tCode    int    `json:\"-\"`\n\tMessage string `json:\"error\"`\n}\n```\nError is a custom error that implements the \\`error\\` interface. When creating errors you should provide a code (could be and http status code) and a message, this way we can handle the errors in a centralized place.\n\n```go\nfunc New(code int, message string) *Error\n```\nNew creates a new instance of Error\n\n```go\nfunc (e *Error) Error() string\n```\n\n","path":"github.com/hellofresh/janus/pkg/errors","name":"errors","synopsis":"Package errors provides a nice way of handling http errors","isRedistributable":true}
