apperr

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package apperr defines the domain error vocabulary shared by every service. Services return these; the single translation point httpx.RenderError maps them to RFC 9457 problem+json. Keeping them here (not in each service package) lets httpx translate without importing the whole service tree.

Index

Constants

View Source
const (
	ErrNotFound        = sentinel("not found")
	ErrForbidden       = sentinel("forbidden")
	ErrConflict        = sentinel("conflict")
	ErrUnauthenticated = sentinel("unauthenticated")
	ErrBadRequest      = sentinel("bad request")
	ErrUnavailable     = sentinel("service unavailable")
	ErrNotImplemented  = sentinel("not implemented")
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Conflict

type Conflict struct{ Detail string }

Conflict carries a specific human detail (e.g. "team name already taken").

func Conflictf

func Conflictf(f string, a ...any) *Conflict

func (*Conflict) Error

func (e *Conflict) Error() string

func (*Conflict) Is

func (e *Conflict) Is(t error) bool

type Forbidden

type Forbidden struct{ Detail string }

Forbidden carries a specific human detail (e.g. "event is not running"). It reports Is(ErrForbidden) so callers can check the sentinel.

func Forbiddenf

func Forbiddenf(f string, a ...any) *Forbidden

func (*Forbidden) Error

func (e *Forbidden) Error() string

func (*Forbidden) Is

func (e *Forbidden) Is(t error) bool

type NotFound

type NotFound struct{ Detail string }

NotFound carries a specific detail; renders 404.

func (*NotFound) Error

func (e *NotFound) Error() string

func (*NotFound) Is

func (e *NotFound) Is(t error) bool

type NotImplemented

type NotImplemented struct{ Detail string }

NotImplemented renders 501; used for endpoints whose contract exists but whose implementation is not wired yet.

func (*NotImplemented) Error

func (e *NotImplemented) Error() string

func (*NotImplemented) Is

func (e *NotImplemented) Is(t error) bool

type RateLimited

type RateLimited struct {
	RetryAfter time.Duration
	Scope      string
}

RateLimited signals a 429 with a Retry-After. Scope labels the metric.

func (*RateLimited) Error

func (e *RateLimited) Error() string

type Unavailable

type Unavailable struct {
	Detail     string
	RetryAfter time.Duration
}

Unavailable carries a specific detail; renders 503 (e.g. runtime unreachable). RetryAfter, when > 0, is surfaced as a Retry-After header — used for load-shed backpressure (e.g. the argon2id hashing gate).

func (*Unavailable) Error

func (e *Unavailable) Error() string

func (*Unavailable) Is

func (e *Unavailable) Is(t error) bool

type Validation

type Validation struct {
	Fields map[string][]string
}

Validation is a set of field-level failures rendered as a 422 with an errors map.

func NewValidation

func NewValidation() *Validation

NewValidation builds an empty Validation error.

func (*Validation) Add

func (v *Validation) Add(field, msg string)

Add appends a message for a field.

func (*Validation) Error

func (v *Validation) Error() string

func (*Validation) HasErrors

func (v *Validation) HasErrors() bool

HasErrors reports whether any field failed.

func (*Validation) OrNil

func (v *Validation) OrNil() error

OrNil returns nil when there are no field errors, else the receiver.

Jump to

Keyboard shortcuts

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