api_errors

package
v0.0.0-...-f59cc51 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2021 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Code

func Code(err error) codes.Code

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

func IsBadRequest

func IsBadRequest(err error) bool

IsBadRequest determines if err is an error which indicates a BadRequest 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 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

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.

Types

type ApiError

type ApiError struct {
	Domain   string            `json:"domain"`
	Reason   string            `json:"reason"`
	Metadata map[string]string `json:"metadata"`
	// contains filtered or unexported fields
}

func BadRequest

func BadRequest(domain, reason, message string) *ApiError

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

func Conflict

func Conflict(domain, reason, message string) *ApiError

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

func Forbidden

func Forbidden(domain, reason, message string) *ApiError

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

func FromError

func FromError(err error) *ApiError

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

func InternalServer

func InternalServer(domain, reason, message string) *ApiError

InternalServer new InternalServer error that is mapped to a 500 response.

func New

func New(code codes.Code, domain, reason, message string) *ApiError

New returns an error object for the code, message.

func Newf

func Newf(code codes.Code, domain, reason, format string, a ...interface{}) *ApiError

Newf New(code fmt.Sprintf(format, a...))

func NotFound

func NotFound(domain, reason, message string) *ApiError

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

func ServiceUnavailable

func ServiceUnavailable(domain, reason, message string) *ApiError

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

func Unauthorized

func Unauthorized(domain, reason, message string) *ApiError

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

func (ApiError) Code

func (e ApiError) Code() uint32

func (ApiError) Data

func (e ApiError) Data() interface{}

func (ApiError) Error

func (e ApiError) Error() string

func (*ApiError) GRPCStatus

func (e *ApiError) GRPCStatus() *status.Status

GRPCStatus returns the Status represented by se.

func (*ApiError) Is

func (e *ApiError) Is(err error) bool

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

func (ApiError) Message

func (e ApiError) Message() string

func (*ApiError) WithMetadata

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

WithMetadata with an MD formed by the mapping of key, value.

Jump to

Keyboard shortcuts

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