apperr

package
v0.1.0 Latest Latest
Warning

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

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

Documentation

Overview

Package apperr is the error vocabulary an application's services share with its transports. Services return these errors, wrapped with a reason; each transport maps them to a response in one place (ginhelpers.Status for gin pages and JSON APIs). The package imports nothing, so services can use it without depending on a transport.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotFound: the thing doesn't exist, or the actor may not know it
	// exists.
	ErrNotFound = errors.New("not found")
	// ErrForbidden: the actor can see the thing but may not do this to it.
	ErrForbidden = errors.New("forbidden")
	// ErrNeedsLogin: an anonymous actor would be allowed after logging in.
	ErrNeedsLogin = errors.New("needs login")
	// ErrConflict: the change collides with existing state. Wrap it with the
	// reason: fmt.Errorf("%w: username is taken", apperr.ErrConflict).
	ErrConflict = errors.New("conflict")
)

Functions

func Invalid

func Invalid(field, message string) error

Invalid returns a ValidationError for field.

Types

type ValidationError

type ValidationError struct {
	Field   string
	Message string
}

ValidationError rejects an input. Message is shown to the user as is, so it reads as a sentence. Field names the input field, or is empty when the error is about the input as a whole.

func (*ValidationError) Error

func (e *ValidationError) Error() string

Jump to

Keyboard shortcuts

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