apperr

package
v0.0.124 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: GPL-3.0 Imports: 2 Imported by: 0 modules, 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

Overview

Package apperr holds the error kinds every layer shares. The store raises ErrNotFound and ErrAlreadyExists, the service layer wraps them or raises its own rejections, and the HTTP layer maps them to statuses — all against these same values, so a handler can tell "not found" from "forbidden" without importing the store, and there is exactly one ErrAlreadyExists.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotFound: the thing asked for does not exist.
	ErrNotFound = errors.New("not found")
	// ErrAlreadyExists: a uniqueness rule refused the write (a duplicate
	// name, slug, key or ID).
	ErrAlreadyExists = errors.New("already exists")
	// ErrForbidden: the thing exists, but the caller may not do this to it.
	ErrForbidden = errors.New("forbidden")
	// ErrValidation: the caller's input breaks a rule (a bound, a required
	// field, an unknown value).
	ErrValidation = errors.New("invalid input")
	// ErrConflict: the request is fine, but the thing's current state refuses
	// it (still in use, changed meanwhile).
	ErrConflict = errors.New("conflict")
)

Functions

func Conflict

func Conflict(format string, args ...any) error

Conflict refuses an action the thing's current state does not allow.

func Forbidden

func Forbidden(format string, args ...any) error

Forbidden refuses an action the caller may not take, saying why.

func Invalid

func Invalid(format string, args ...any) error

Invalid refuses input that breaks a rule, saying which.

func Message

func Message(err, kind error) (string, bool)

Message returns the user-facing text of err's Rejection of the given kind, if it carries one.

func NotFound

func NotFound(format string, args ...any) error

NotFound reports a missing thing in words the caller can act on.

func Reject

func Reject(kind error, format string, args ...any) error

Reject returns a refusal of the given kind carrying a user-facing message.

Types

type Rejection

type Rejection struct {
	Kind    error
	Message string
}

Rejection is a refusal whose message is written for the person who asked: the HTTP layer shows Message as is, and Kind (one of the sentinels above, or a service sentinel) picks the status. errors.Is(r, r.Kind) holds, so a typed refusal is still matched like the bare sentinel.

func (*Rejection) Error

func (r *Rejection) Error() string

func (*Rejection) Unwrap

func (r *Rejection) Unwrap() error

Unwrap exposes Kind to errors.Is / errors.As.

Jump to

Keyboard shortcuts

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