{"modulePath":"github.com/stacklok/toolhive","version":"v0.9.0","isLatest":false,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package errors\n\nPackage errors provides error types with HTTP status codes for API error handling.\n\n## Functions\n\n```go\nfunc Code(err error) int\n```\nCode extracts the HTTP status code from an error. It unwraps the error chain looking for a CodedError. If no CodedError is found, it returns http.StatusInternalServerError (500).\n\n```go\nfunc New(message string, code int) error\n```\nNew creates a new error with the given message and HTTP status code. This is a convenience function equivalent to WithCode(errors.New(message), code).\n\n```go\nfunc WithCode(err error, code int) error\n```\nWithCode wraps an error with an HTTP status code. The returned error implements Unwrap() for use with errors.Is() and errors.As(). If err is nil, WithCode returns nil.\n\n## Types\n\n```go\ntype CodedError struct {\n\t// contains filtered or unexported fields\n}\n```\nCodedError wraps an error with an HTTP status code. This allows errors to carry their intended HTTP response code through the call stack, enabling centralized error handling in API handlers.\n\n```go\nfunc (e *CodedError) Error() string\n```\nError implements the error interface.\n\n```go\nfunc (e *CodedError) HTTPCode() int\n```\nHTTPCode returns the HTTP status code associated with this error.\n\n```go\nfunc (e *CodedError) Unwrap() error\n```\nUnwrap returns the underlying error for errors.Is() and errors.As() compatibility.\n\n","path":"github.com/stacklok/toolhive/pkg/errors","name":"errors","synopsis":"Package errors provides error types with HTTP status codes for API error handling.","isRedistributable":true}
