apperror

package
v0.0.0-...-98bbd2d Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: MIT Imports: 3 Imported by: 1

Documentation

Overview

Package apperror provides errors with common semantic connotations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Conflict

func Conflict(msg string, a ...any) error

Conflict creates a new conflict error.

func Forbidden

func Forbidden(msg string, a ...any) error

Forbidden creates a new forbidden error.

func IsConflict

func IsConflict(err error) bool

IsConflict checks if the error is a conflict error.

func IsForbidden

func IsForbidden(err error) bool

IsForbidden checks if the error is a forbidden error.

func IsNotFound

func IsNotFound(err error) bool

IsNotFound checks if the error is a not found error.

func IsNotModified

func IsNotModified(err error) bool

IsNotModified checks if the error is a not modified error.

func IsPreconditionFailed

func IsPreconditionFailed(err error) bool

IsPreconditionFailed checks if the error is a precondition failed error.

func IsTimeout

func IsTimeout(err error) bool

IsTimeout checks if the error is a timeout error.

func IsTooManyRequests

func IsTooManyRequests(err error) bool

IsTooManyRequests checks if the error is a too many requests error.

func IsUnauthorized

func IsUnauthorized(err error) bool

IsUnauthorized checks if the error is a unauthorized error.

func IsValidation

func IsValidation(err error) bool

IsValidation checks fit he error is a validation error.

func NotFound

func NotFound(msg string, a ...any) error

NotFound creates a new not found error.

func NotModified

func NotModified(msg string, a ...any) error

NotModified creates a new not modified error. This is usually a sentinel error and does not indicate a problem.

func PreconditionFailed

func PreconditionFailed(msg string, a ...any) error

PreconditionFailed creates a new precondition failed error.

func Timeout

func Timeout(msg string, a ...any) error

Timeout creates a new timeout error.

func TooManyRequests

func TooManyRequests(msg string, a ...any) error

TooManyRequests creates a new too many requests error.

func Unauthorized

func Unauthorized(msg string, a ...any) error

Unauthorized creates a new unauthorized error.

func Validation

func Validation(msg string, a ...any) error

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
	UnauthorizedKind       Kind = 401
	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.

func KindOf

func KindOf(err error) Kind

KindOf allows potentially faster checking of multiple error types.

func (Kind) String

func (i Kind) String() string

Jump to

Keyboard shortcuts

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