Documentation ¶
Overview ¶
Package apperror provides errors with common semantic connotations.
Index ¶
- func Conflict(msg string, a ...any) error
- func Forbidden(msg string, a ...any) error
- func IsConflict(err error) bool
- func IsForbidden(err error) bool
- func IsNotFound(err error) bool
- func IsNotModified(err error) bool
- func IsPreconditionFailed(err error) bool
- func IsTimeout(err error) bool
- func IsTooManyRequests(err error) bool
- func IsUnauthorized(err error) bool
- func IsValidation(err error) bool
- func NotFound(msg string, a ...any) error
- func NotModified(msg string, a ...any) error
- func PreconditionFailed(msg string, a ...any) error
- func Timeout(msg string, a ...any) error
- func TooManyRequests(msg string, a ...any) error
- func Unauthorized(msg string, a ...any) error
- func Validation(msg string, a ...any) error
- type Kind
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsConflict ¶
IsConflict checks if the error is a conflict error.
func IsForbidden ¶
IsForbidden checks if the error is a forbidden error.
func IsNotFound ¶
IsNotFound checks if the error is a not found error.
func IsNotModified ¶
IsNotModified checks if the error is a not modified error.
func IsPreconditionFailed ¶
IsPreconditionFailed checks if the error is a precondition failed error.
func IsTooManyRequests ¶
IsTooManyRequests checks if the error is a too many requests error.
func IsUnauthorized ¶
IsUnauthorized checks if the error is a unauthorized error.
func IsValidation ¶
IsValidation checks fit he error is a validation error.
func NotModified ¶
NotModified creates a new not modified error. This is usually a sentinel error and does not indicate a problem.
func PreconditionFailed ¶
PreconditionFailed creates a new precondition failed error.
func TooManyRequests ¶
TooManyRequests creates a new too many requests error.
func Unauthorized ¶
Unauthorized creates a new unauthorized error.
func Validation ¶
Validation creates a new validation error.
Types ¶
type Kind ¶
type Kind int
Kind indicates the category of error. There is one for each Is* function in this package.
const ( UnknownKind Kind = 0 NotModifiedKind Kind = 304 ValidationKind Kind = 400 ForbiddenKind Kind = 403 NotFoundKind Kind = 404 ConflictKind Kind = 409 PreconditionFailedKind Kind = 412 TooManyRequestsKind Kind = 429 TimeoutKind Kind = 504 )
The values below don't really matter, but they have been chosen to match the HTTP codes because a lot of developers are familiar with them.
The choice for TimeoutKind is a bit tricky, but I want to be able to distinguish between a timeout and other kinds of server errors, which would be hard if we went with 500.