Documentation
¶
Overview ¶
Package errors provides error handling implementations for the neoma framework, including RFC 9457 Problem Details support for standardized HTTP API error responses.
Index ¶
- func ErrorBadRequest(msg string, errs ...error) core.Error
- func ErrorConflict(msg string, errs ...error) core.Error
- func ErrorForbidden(msg string, errs ...error) core.Error
- func ErrorInternalServerError(msg string, errs ...error) core.Error
- func ErrorN(status int, msg string, errs ...error) core.Error
- func ErrorNotFound(msg string, errs ...error) core.Error
- func ErrorTooManyRequests(msg string, errs ...error) core.Error
- func ErrorUnauthorized(msg string, errs ...error) core.Error
- func ErrorUnprocessableEntity(msg string, errs ...error) core.Error
- func Status304NotModified() core.Error
- type NoopHandler
- func (f *NoopHandler) ErrorContentType(ct string) string
- func (f *NoopHandler) ErrorSchema(_ core.Registry) *core.Schema
- func (f *NoopHandler) NewError(status int, msg string, _ ...error) core.Error
- func (f *NoopHandler) NewErrorWithContext(_ core.Context, status int, msg string, _ ...error) core.Error
- type ProblemDetail
- type RFC9457Handler
- func (f *RFC9457Handler) ErrorContentType(ct string) string
- func (f *RFC9457Handler) ErrorSchema(registry core.Registry) *core.Schema
- func (f *RFC9457Handler) GetTypeBaseURI() string
- func (f *RFC9457Handler) NewError(status int, msg string, errs ...error) core.Error
- func (f *RFC9457Handler) NewErrorWithContext(ctx core.Context, status int, msg string, errs ...error) core.Error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ErrorBadRequest ¶
ErrorBadRequest creates a 400 Bad Request problem detail error.
func ErrorConflict ¶
ErrorConflict creates a 409 Conflict problem detail error.
func ErrorForbidden ¶
ErrorForbidden creates a 403 Forbidden problem detail error.
func ErrorInternalServerError ¶
ErrorInternalServerError creates a 500 Internal Server Error problem detail error.
func ErrorNotFound ¶
ErrorNotFound creates a 404 Not Found problem detail error.
func ErrorTooManyRequests ¶
ErrorTooManyRequests creates a 429 Too Many Requests problem detail error.
func ErrorUnauthorized ¶
ErrorUnauthorized creates a 401 Unauthorized problem detail error.
func ErrorUnprocessableEntity ¶
ErrorUnprocessableEntity creates a 422 Unprocessable Entity problem detail error.
func Status304NotModified ¶
Status304NotModified creates a 304 Not Modified error, typically used for conditional request handling.
Types ¶
type NoopHandler ¶
type NoopHandler struct{}
NoopHandler is a minimal error handler that produces plain errors without RFC 9457 Problem Details structure. It is useful for testing or when structured error responses are not needed.
func (*NoopHandler) ErrorContentType ¶
func (f *NoopHandler) ErrorContentType(ct string) string
ErrorContentType returns the content type unchanged.
func (*NoopHandler) ErrorSchema ¶
func (f *NoopHandler) ErrorSchema(_ core.Registry) *core.Schema
ErrorSchema returns nil because NoopHandler does not define an error schema.
func (*NoopHandler) NewError ¶
NewError creates a minimal error with the given status and message, ignoring any additional errors.
func (*NoopHandler) NewErrorWithContext ¶
func (f *NoopHandler) NewErrorWithContext(_ core.Context, status int, msg string, _ ...error) core.Error
NewErrorWithContext creates a minimal error, ignoring the request context.
type ProblemDetail ¶
type ProblemDetail struct {
Type string `` /* 170-byte string literal not displayed */
Title string `json:"title,omitempty" example:"Bad Request" doc:"A short, human-readable summary of the problem type."`
Status int `json:"status,omitempty" example:"400" doc:"HTTP status code"`
Detail string `` /* 153-byte string literal not displayed */
Instance string `` /* 163-byte string literal not displayed */
Errors []*core.ErrorDetail `json:"errors,omitempty" doc:"Optional list of individual error details"`
}
ProblemDetail represents an RFC 9457 Problem Details object for HTTP APIs. It carries a type URI, human-readable title and detail, the HTTP status code, and an optional list of granular error details.
func (*ProblemDetail) Add ¶
func (e *ProblemDetail) Add(err error)
Add appends an error to the problem's error details list. If the error implements core.ErrorDetailer, its structured detail is used directly.
func (*ProblemDetail) ContentType ¶
func (e *ProblemDetail) ContentType(ct string) string
ContentType returns the appropriate RFC 9457 content type for the given base content type (e.g. "application/problem+json" for "application/json").
func (*ProblemDetail) Error ¶
func (e *ProblemDetail) Error() string
Error returns the problem detail message, satisfying the error interface.
func (*ProblemDetail) GetType ¶
func (e *ProblemDetail) GetType() string
GetType returns the problem type URI.
func (*ProblemDetail) StatusCode ¶
func (e *ProblemDetail) StatusCode() int
StatusCode returns the HTTP status code for this problem.
type RFC9457Handler ¶
RFC9457Handler creates RFC 9457 Problem Details errors. It implements the core.ErrorHandler interface and supports configurable type URIs and per-request instance URIs.
func NewRFC9457Handler ¶
func NewRFC9457Handler() *RFC9457Handler
NewRFC9457Handler returns a new RFC9457Handler with default settings.
func NewRFC9457HandlerWithConfig ¶
func NewRFC9457HandlerWithConfig(typeBaseURI string, instanceFunc func(core.Context) string) *RFC9457Handler
NewRFC9457HandlerWithConfig returns a new RFC9457Handler with a custom type base URI and an optional function to generate per-request instance URIs.
func (*RFC9457Handler) ErrorContentType ¶
func (f *RFC9457Handler) ErrorContentType(ct string) string
ErrorContentType returns the RFC 9457 content type for error responses.
func (*RFC9457Handler) ErrorSchema ¶
func (f *RFC9457Handler) ErrorSchema(registry core.Registry) *core.Schema
ErrorSchema returns the JSON Schema for ProblemDetail using the given registry.
func (*RFC9457Handler) GetTypeBaseURI ¶
func (f *RFC9457Handler) GetTypeBaseURI() string
GetTypeBaseURI returns the base URI used to construct problem type URIs.
func (*RFC9457Handler) NewError ¶
NewError creates a new ProblemDetail with the given status, message, and optional underlying errors.
func (*RFC9457Handler) NewErrorWithContext ¶
func (f *RFC9457Handler) NewErrorWithContext(ctx core.Context, status int, msg string, errs ...error) core.Error
NewErrorWithContext creates a new ProblemDetail like NewError, but also sets the instance URI using the configured InstanceFunc and request context.