errcode

package
v0.34.1 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrCodeNotFound     = "ERR_NOT_FOUND"
	ErrCodeValidation   = "ERR_VALIDATION"
	ErrCodeUnauthorized = "ERR_UNAUTHORIZED"
	ErrCodeForbidden    = "ERR_FORBIDDEN"
	ErrCodeRateLimited  = "ERR_RATE_LIMITED"
	ErrCodeConflict     = "ERR_CONFLICT"
	ErrCodeTimeout      = "ERR_TIMEOUT"
	ErrCodeDBConnection = "ERR_DB_CONNECTION"
	ErrCodeDBQuery      = "ERR_DB_QUERY"
	ErrCodeNATS         = "ERR_NATS"
	ErrCodeInternal     = "ERR_INTERNAL"
)

Variables

This section is empty.

Functions

func ErrDBConnection

func ErrDBConnection(inner error) error

func ErrDBQuery

func ErrDBQuery(op, table string, inner error) error

func ErrForbidden

func ErrForbidden(resource string) error

func ErrInternal

func ErrInternal(inner error) error

func ErrNATSPublish

func ErrNATSPublish(subject string, inner error) error

func ErrNotFound

func ErrNotFound(resource string, id any) error

func ErrRateLimited

func ErrRateLimited(retryAfter int) error

func ErrStatus

func ErrStatus(status int, msg string, kv ...any) error

func ErrTimeout

func ErrTimeout(operation string) error

func ErrUnauthorized

func ErrUnauthorized(reason string) error

func ErrValidation

func ErrValidation(field, constraint string, val any) error

func WriteProblem added in v0.34.1

func WriteProblem(c fiber.Ctx, status int, code, detail string) error

WriteProblem answers with an RFC 9457 problem document. Middleware and entry handlers that must answer directly (not through the server error handler) use it so every error shares one shape. The type is "about:blank", the standard default when no problem registry is configured.

func WriteProblemWith added in v0.34.1

func WriteProblemWith(c fiber.Ctx, status int, code, detail string, extra map[string]any) error

WriteProblemWith is WriteProblem plus extra extension members (the RFC allows them). Used when the error carries structured data, like the failing fields of an input validation.

Types

type Problem added in v0.34.1

type Problem struct {
	// Type identifies the problem type ("about:blank", the RFC default, when
	// the writer has no registry base).
	Type string `json:"type"`
	// Title is the short summary of the type (the HTTP status phrase).
	Title string `json:"title"`
	// Status repeats the HTTP status code in the body, per the RFC.
	Status int `json:"status"`
	// Detail explains this occurrence.
	Detail string `json:"detail,omitempty"`
	// Instance identifies this occurrence (the request path).
	Instance string `json:"instance,omitempty"`
	// Code is the machine-readable error code (extension).
	Code string `json:"code,omitempty"`
}

Problem is an RFC 9457 (Problem Details for HTTP APIs) document: the error body every service answers with, served as application/problem+json.

`code` is a registered extension carrying the machine-readable error code; a client that only knows the standard ignores it.

Jump to

Keyboard shortcuts

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