errors

package
v10.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package errors provides a way to return detailed information for an request error. The error is normally JSON encoded.

Index

Constants

View Source
const (
	DefaultBadRequestID            = "bad_request"
	DefaultUnauthorizedID          = "unauthorized"
	DefaultForbiddenID             = "forbidden"
	DefaultNotFoundID              = "not_found"
	DefaultMethodNotAllowedID      = "method_not_allowed"
	DefaultTooManyRequestsID       = "too_many_requests"
	DefaultRequestEntityTooLargeID = "request_entity_too_large"
	DefaultInternalServerErrorID   = "internal_server_error"
	DefaultConflictID              = "conflict"
	DefaultRequestTimeoutID        = "request_timeout"
)

Variables

View Source
var (
	WithStack = errors.WithStack
	Wrap      = errors.Wrap
	Wrapf     = errors.Wrapf
	Is        = errors.Is
	Errorf    = errors.Errorf
)

Define alias

Functions

func BadRequest

func BadRequest(id, format string, a ...interface{}) error

BadRequest generates a 400 error.

func Conflict

func Conflict(id, format string, a ...interface{}) error

Conflict generates a 409 error.

func Equal

func Equal(err1 error, err2 error) bool

Equal tries to compare errors

func Forbidden

func Forbidden(id, format string, a ...interface{}) error

Forbidden generates a 403 error.

func InternalServerError

func InternalServerError(id, format string, a ...interface{}) error

InternalServerError generates a 500 error.

func MethodNotAllowed

func MethodNotAllowed(id, format string, a ...interface{}) error

MethodNotAllowed generates a 405 error.

func New

func New(id, detail string, code int32) error

New generates a custom error.

func NotFound

func NotFound(id, format string, a ...interface{}) error

NotFound generates a 404 error.

func RequestEntityTooLarge

func RequestEntityTooLarge(id, format string, a ...interface{}) error

RequestEntityTooLarge generates a 413 error.

func Timeout

func Timeout(id, format string, a ...interface{}) error

Timeout generates a 408 error.

func TooManyRequests

func TooManyRequests(id, format string, a ...interface{}) error

TooManyRequests generates a 429 error.

func Unauthorized

func Unauthorized(id, format string, a ...interface{}) error

Unauthorized generates a 401 error.

Types

type Error

type Error struct {
	ID     string `json:"id,omitempty"`
	Code   int32  `json:"code,omitempty"`
	Detail string `json:"detail,omitempty"`
	Status string `json:"status,omitempty"`
}

Customize the error structure for implementation errors.Error interface

func As

func As(err error) (*Error, bool)

As finds the first error in err's chain that matches *Error

func FromError

func FromError(err error) *Error

FromError try to convert go error to *Error

func Parse

func Parse(err string) *Error

Parse tries to parse a JSON string into an error. If that fails, it will set the given string as the error detail.

func (*Error) Error

func (e *Error) Error() string

type MultiError

type MultiError struct {
	Errors []error
	// contains filtered or unexported fields
}

func NewMultiError

func NewMultiError() *MultiError

func (*MultiError) Append

func (e *MultiError) Append(err error)

func (*MultiError) AppendWithLock

func (e *MultiError) AppendWithLock(err error)

func (*MultiError) Error

func (e *MultiError) Error() string

func (*MultiError) HasErrors

func (e *MultiError) HasErrors() bool

Jump to

Keyboard shortcuts

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