Documentation
¶
Overview ¶
Package apierror contains a variety of marshalable API errors that adhere to a unified error response convention.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type APIError ¶
type APIError struct { // InternalError is an additional error that might be associated with the // API error. It's not returned in the API error response, but is logged in // API endpoint execution to provide extra information for operators. InternalError error `json:"-"` // Message is a descriptive, human-friendly message indicating what went // wrong. Try to make error messages as actionable as possible to help the // caller easily fix what went wrong. Message string `json:"message"` // StatusCode is the API error's HTTP status code. It's not marshaled to // JSON, but determines how the error is written to a response. StatusCode int `json:"-"` }
APIError is a struct that's embedded on a more specific API error struct (as seen below), and which provides a JSON serialization and a wait to conveniently write itself to an HTTP response.
APIErrorInterface should be used with errors.As instead of this struct.
type BadRequest ¶
type BadRequest struct {
APIError
}
func NewBadRequest ¶
func NewBadRequest(format string, a ...any) *BadRequest
type Interface ¶
type Interface interface { Error() string GetInternalError() error SetInternalError(internalErr error) Write(ctx context.Context, logger *slog.Logger, w http.ResponseWriter) }
Interface is an interface to an API error. This is needed for use with errors.As because APIError itself is embedded on another error struct, and won't be usable as an errors.As target.
type InternalServerError ¶
type InternalServerError struct {
APIError
}
func NewInternalServerError ¶
func NewInternalServerError(format string, a ...any) *InternalServerError
type ServiceUnavailable ¶
type ServiceUnavailable struct {
}func NewServiceUnavailable ¶
func NewServiceUnavailable(format string, a ...any) *ServiceUnavailable
Click to show internal directories.
Click to hide internal directories.