apierror

package
v0.4.0-rc.16-linux-arm64 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2026 License: Apache-2.0 Imports: 9 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	// Authentication & Authorization
	CodeAuthUnauthorized          = "AUTH_UNAUTHORIZED"
	CodeAuthForbidden             = "AUTH_FORBIDDEN"
	CodeAuthUserPrincipalRequired = "AUTH_USER_PRINCIPAL_REQUIRED"
	CodeCSRFInvalid               = "CSRF_INVALID"
	CodeRateLimited               = "RATE_LIMITED"

	// Validation
	CodeValidationFailed        = "VALIDATION_FAILED"
	CodeValidationRequiredField = "VALIDATION_REQUIRED_FIELD"
	CodeValidationInvalidFormat = "VALIDATION_INVALID_FORMAT"

	// Validation - Specific field types
	CodeEmailInvalid       = "EMAIL_INVALID"
	CodeValueTooShort      = "VALUE_TOO_SHORT"
	CodeValueTooLong       = "VALUE_TOO_LONG"
	CodeValueInvalidLength = "VALUE_INVALID_LENGTH"
	CodeValueNotInList     = "VALUE_NOT_IN_LIST"
	CodeUUIDInvalid        = "UUID_INVALID"
	CodeURLInvalid         = "URL_INVALID"
	CodeDatetimeInvalid    = "DATETIME_INVALID"

	// System
	CodeInternalServerError = "INTERNAL_SERVER_ERROR"
	CodeNotImplemented      = "NOT_IMPLEMENTED"
	CodeMethodNotAllowed    = "METHOD_NOT_ALLOWED"
)

Variables

This section is empty.

Functions

func Middleware

func Middleware() fiber.ErrorHandler

Middleware is a Fiber middleware that converts errors to structured API responses

func RecoverPanic

func RecoverPanic(_ fiber.Ctx, _ any) error

RecoverPanic discards the panic value and returns a fixed server error.

Types

type Error

type Error struct {
	Code             string            `json:"code"`
	Message          string            `json:"message"`
	DetailedError    string            `json:"detailed_error,omitempty"`
	ValidationErrors []ValidationError `json:"validation_errors,omitempty"`
	RequestID        string            `json:"request_id,omitempty"`

	// Internal fields (not serialized)
	HTTPStatus int `json:"-"`
}

Error represents a structured API error

func CSRFInvalid

func CSRFInvalid() *Error

func Forbidden

func Forbidden(resource, action string) *Error

func InternalServerError

func InternalServerError() *Error

func InvalidRequestBody

func InvalidRequestBody() *Error

func New

func New(httpStatus int, code, message string) *Error

New creates a new API error

func NotImplemented

func NotImplemented() *Error

func RateLimited

func RateLimited() *Error

func Unauthorized

func Unauthorized() *Error

func UserPrincipalRequired

func UserPrincipalRequired() *Error

func ValidationFailed

func ValidationFailed(message string) *Error

func (*Error) Error

func (e *Error) Error() string

Error implements the error interface

func (*Error) WithDetailedError

func (e *Error) WithDetailedError(detailedError string) *Error

WithDetailedError adds backend diagnostic details for disclosure UIs.

type ErrorResponse

type ErrorResponse struct {
	Error *Error `json:"error"`
}

ErrorResponse wraps the error for API responses

func OapiValidationFailed

func OapiValidationFailed(err error, requestID string) ErrorResponse

OapiValidationFailed exposes only validation metadata declared in the schema.

type ValidationError

type ValidationError struct {
	Field   string `json:"field"`
	Code    string `json:"code"`
	Message string `json:"message"`
}

ValidationError represents a field-level validation error

Jump to

Keyboard shortcuts

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