errors

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ClientClosed is non-standard http status code,
	// which defined by nginx.
	// https://httpstatus.in/499/
	ClientClosed = 499
)

Variables

This section is empty.

Functions

func Code

func Code(err error) int

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

func Errorf

func Errorf(code int, message, format string, a ...any) error

func FromGRPCCode

func FromGRPCCode(code codes.Code) int

FromGRPCCode converts a gRPC error code into the corresponding HTTP response status.

func IsBadRequest

func IsBadRequest(err error) bool

IsBadRequest determines if err is an error which indicates a BadRequest error. It supports wrapped errors.

func IsClientClosed

func IsClientClosed(err error) bool

IsClientClosed determines if err is an error which indicates a IsClientClosed error. It supports wrapped errors.

func IsConflict

func IsConflict(err error) bool

IsConflict determines if err is an error which indicates a Conflict error. It supports wrapped errors.

func IsForbidden

func IsForbidden(err error) bool

IsForbidden determines if err is an error which indicates a Forbidden error. It supports wrapped errors.

func IsGatewayTimeout

func IsGatewayTimeout(err error) bool

IsGatewayTimeout determines if err is an error which indicates a GatewayTimeout error. It supports wrapped errors.

func IsInternalServer

func IsInternalServer(err error) bool

func IsNotFound

func IsNotFound(err error) bool

IsNotFound determines if err is an error which indicates an NotFound error. It supports wrapped errors.

func IsServiceUnavailable

func IsServiceUnavailable(err error) bool

IsServiceUnavailable determines if err is an error which indicates a Unavailable error. It supports wrapped errors.

func IsUnauthorized

func IsUnauthorized(err error) bool

IsUnauthorized determines if err is an error which indicates a Unauthorized error. It supports wrapped errors.

func Message

func Message(err error) string

func ToGRPCCode

func ToGRPCCode(code int) codes.Code

ToGRPCCode converts an HTTP error code into the corresponding gRPC response status.

Types

type Converter

type Converter interface {
	// ToGRPCCode converts an HTTP error code into the corresponding gRPC response status.
	ToGRPCCode(code int) codes.Code
	// FromGRPCCode converts a gRPC error code into the corresponding HTTP response status.
	FromGRPCCode(code codes.Code) int
}
var DefaultConverter Converter = statusConverter{}

type Error

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

func ErrBadRequest

func ErrBadRequest(detail string) *Error

ErrBadRequest new BadRequest error that is mapped to a 400 response.

func ErrBadRequestf

func ErrBadRequestf(format string, args ...any) *Error

ErrBadRequestf new BadRequest error that is mapped to a 400 response.

func ErrClientClosed

func ErrClientClosed(message string) *Error

ErrClientClosed new ClientClosed error that is mapped to a HTTP 499 response.

func ErrClientClosedf

func ErrClientClosedf(format string, args ...any) *Error

ErrClientClosed new ClientClosed error that is mapped to a HTTP 499 response.

func ErrConflict

func ErrConflict(detail string) *Error

ErrConflict new Conflict error that is mapped to a 409 response.

func ErrConflictf

func ErrConflictf(format string, args ...any) *Error

ErrConflictf new Conflict error that is mapped to a 409 response.

func ErrForbidden

func ErrForbidden(detail string) *Error

ErrForbidden new Forbidden error that is mapped to a 403 response.

func ErrForbiddenf

func ErrForbiddenf(format string, args ...any) *Error

ErrForbiddenf new Forbidden error that is mapped to a 403 response.

func ErrGatewayTimeout

func ErrGatewayTimeout(detail string) *Error

ErrGatewayTimeout new GatewayTimeout error that is mapped to a HTTP 504 response.

func ErrGatewayTimeoutf

func ErrGatewayTimeoutf(format string, args ...any) *Error

ErrGatewayTimeoutf new GatewayTimeout error that is mapped to a HTTP 504 response.

func ErrInternalServer

func ErrInternalServer(detail string) *Error

func ErrInternalServerf

func ErrInternalServerf(format string, args ...any) *Error

func ErrNotFound

func ErrNotFound(detail string) *Error

ErrNotFound new NotFound error that is mapped to a 404 response.

func ErrNotFoundf

func ErrNotFoundf(format string, args ...any) *Error

ErrNotFoundf new NotFound error that is mapped to a 404 response.

func ErrServiceUnavailable

func ErrServiceUnavailable(detail string) *Error

ErrServiceUnavailable new ServiceUnavailable error that is mapped to a HTTP 503 response.

func ErrServiceUnavailablef

func ErrServiceUnavailablef(format string, args ...any) *Error

ErrServiceUnavailablef new ServiceUnavailable error that is mapped to a HTTP 503 response.

func ErrUnauthorized

func ErrUnauthorized(detail string) *Error

ErrUnauthorized new Unauthorized error that is mapped to a 401 response.

func ErrUnauthorizedf

func ErrUnauthorizedf(format string, args ...any) *Error

ErrUnauthorized new Unauthorized error that is mapped to a 401 response.

func FromError

func FromError(err error) *Error

func New

func New(code int, message, detail string) *Error

func Newf

func Newf(code int, message, format string, a ...any) *Error

func Parse

func Parse(err string) *Error

func (*Error) Error

func (x *Error) Error() string

func (*Error) GRPCStatus

func (x *Error) GRPCStatus() *status.Status

GRPCStatus returns the Status represented by se.

func (*Error) Is

func (x *Error) Is(err error) bool

Is matches each error in the chain with the target value.

func (*Error) WithMetadata

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

Jump to

Keyboard shortcuts

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