errors

package
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 22, 2026 License: MPL-2.0 Imports: 5 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func ErrorBadRequest

func ErrorBadRequest(msg string, errs ...error) core.Error

ErrorBadRequest creates a 400 Bad Request problem detail error.

func ErrorConflict

func ErrorConflict(msg string, errs ...error) core.Error

ErrorConflict creates a 409 Conflict problem detail error.

func ErrorForbidden

func ErrorForbidden(msg string, errs ...error) core.Error

ErrorForbidden creates a 403 Forbidden problem detail error.

func ErrorInternalServerError

func ErrorInternalServerError(msg string, errs ...error) core.Error

ErrorInternalServerError creates a 500 Internal Server Error problem detail error.

func ErrorN

func ErrorN(status int, msg string, errs ...error) core.Error

ErrorN creates a problem detail error with an arbitrary HTTP status code.

func ErrorNotFound

func ErrorNotFound(msg string, errs ...error) core.Error

ErrorNotFound creates a 404 Not Found problem detail error.

func ErrorTooManyRequests

func ErrorTooManyRequests(msg string, errs ...error) core.Error

ErrorTooManyRequests creates a 429 Too Many Requests problem detail error.

func ErrorUnauthorized

func ErrorUnauthorized(msg string, errs ...error) core.Error

ErrorUnauthorized creates a 401 Unauthorized problem detail error.

func ErrorUnprocessableEntity

func ErrorUnprocessableEntity(msg string, errs ...error) core.Error

ErrorUnprocessableEntity creates a 422 Unprocessable Entity problem detail error.

func Status304NotModified

func Status304NotModified() core.Error

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 NewNoopHandler

func NewNoopHandler() *NoopHandler

NewNoopHandler returns a new NoopHandler.

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

func (f *NoopHandler) NewError(status int, msg string, _ ...error) core.Error

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

type RFC9457Handler struct {
	TypeBaseURI  string
	InstanceFunc func(ctx core.Context) string
}

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

func (f *RFC9457Handler) NewError(status int, msg string, errs ...error) core.Error

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL