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 ¶
func WithInternalError ¶
WithInternalError is a convenience function for assigning an internal error to the given API error and returning it.
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.
func (*APIError) GetInternalError ¶
func (*APIError) SetInternalError ¶
type BadRequest ¶
type BadRequest struct {
APIError
}
func NewBadRequest ¶
func NewBadRequest(message string) *BadRequest
func NewBadRequestf ¶
func NewBadRequestf(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(message string) *InternalServerError
func NewInternalServerErrorf ¶
func NewInternalServerErrorf(format string, a ...any) *InternalServerError
type RequestEntityTooLarge ¶
type RequestEntityTooLarge struct {
APIError
}
func NewRequestEntityTooLarge ¶
func NewRequestEntityTooLarge(message string) *RequestEntityTooLarge
type ServiceUnavailable ¶
type ServiceUnavailable struct {
}
func NewServiceUnavailable ¶
func NewServiceUnavailable(message string) *ServiceUnavailable
func NewServiceUnavailablef ¶
func NewServiceUnavailablef(format string, a ...any) *ServiceUnavailable
type Unauthorized ¶
type Unauthorized struct {
}
func NewUnauthorized ¶
func NewUnauthorized(format string, a ...any) *Unauthorized