apierror

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

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

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(message, requestID string, statusCode int) ErrorResponse

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