Documentation
¶
Overview ¶
Package apperror describes safe application failures without transport dependencies. Wrap errors with fmt.Errorf("operation: %w", err); use errors.Is/As to inspect them.
Index ¶
- type Code
- type Error
- func Conflict(message string) *Error
- func Forbidden(message string) *Error
- func Internal(message string) *Error
- func InvalidFields(fields map[string][]string) *Error
- func InvalidInput(message string) *Error
- func New(code Code, message string) *Error
- func NotFound(message string) *Error
- func RateLimited(message string) *Error
- func Unauthenticated(message string) *Error
- func Unavailable(message string) *Error
- func Validation(message string) *Error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Code ¶
type Code string
Code classifies a failure independently of HTTP or gRPC status codes. Transport adapters must treat unknown codes as internal failures.
const ( CodeInternal Code = "internal_error" CodeInvalidInput Code = "invalid_input" CodeValidation Code = "validation_failed" CodeUnauthenticated Code = "unauthenticated" CodeForbidden Code = "forbidden" CodeNotFound Code = "not_found" CodeConflict Code = "conflict" CodeRateLimited Code = "rate_limited" )
type Error ¶
type Error struct {
// contains filtered or unexported fields
}
Error carries an explicitly public code and message. Fields are private so package-level domain errors can be shared safely between concurrent callers. Error identity is pointer identity: errors.Is matches the original sentinel.
func InvalidFields ¶
InvalidFields copies field errors. Keys are public input names, using dot paths for nested fields. Values are safe messages, never submitted values.
func InvalidInput ¶
InvalidInput creates an error with CodeInvalidInput.
func New ¶
New creates an application error. Code and message must never contain secrets, raw database errors, or untrusted input. Internal errors are hidden by transports.
func RateLimited ¶
RateLimited creates an error with CodeRateLimited.
func Unauthenticated ¶
Unauthenticated creates an error with CodeUnauthenticated.
func Unavailable ¶
Unavailable creates an error with CodeUnavailable.
func Validation ¶
Validation creates an error with CodeValidation.