errors

package
v0.5.12 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2024 License: MIT Imports: 2 Imported by: 1

Documentation

Overview

nolint:gomnd

Index

Constants

View Source
const (
	UnknownCode = 500
)

Variables

This section is empty.

Functions

func As

func As(err error, target interface{}) bool

func Code

func Code(err error) int

Code returns the http code for an error. It supports wrapped errors.

func Errorf

func Errorf(code int, format string, a ...interface{}) error

func Is

func Is(err, target error) bool

func IsBadRequest

func IsBadRequest(err error) bool

func IsForbidden

func IsForbidden(err error) bool

func IsInternalServer

func IsInternalServer(err error) bool

IsInternalServer determines if err is an error which indicates an Internal error. It supports wrapped errors.

func IsNotFound

func IsNotFound(err error) bool

func IsUnauthorized

func IsUnauthorized(err error) bool

func Unwrap

func Unwrap(err error) error

Types

type Error

type Error struct {
	Code     int               `json:"code,omitempty"`
	Message  string            `json:"message,omitempty"`
	Metadata map[string]string `json:"metadata,omitempty"`
}

func BadRequest

func BadRequest(reason, message string) *Error

func Forbidden

func Forbidden(message string) *Error

func FromError

func FromError(err error) *Error

FromError try to convert an error to *Error. It supports wrapped errors.

func InternalServer

func InternalServer(message string) *Error

func New

func New(code int, message string) *Error

func NotFound

func NotFound(message string) *Error

func Unauthorized

func Unauthorized(message string) *Error

func (Error) Error

func (e Error) Error() string

func (Error) GetCode

func (x Error) GetCode() int

func (Error) GetMessage

func (x Error) GetMessage() string

func (Error) GetMetadata

func (x Error) GetMetadata() map[string]string

func (Error) Is

func (e Error) Is(err error) bool

func (*Error) WithMetadata

func (e *Error) WithMetadata(md map[string]string) *Error

type IgnoreError added in v0.1.23

type IgnoreError interface {
	Ignore() bool
}

type RespError added in v0.4.2

type RespError interface {
	GetCode() int
	GetMessage() string
}

Jump to

Keyboard shortcuts

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