errors

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: May 21, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	InternalError = "Service Internal Error"
)

Variables

This section is empty.

Functions

func Convert

func Convert(err error) *status.Status

func RegisterErrCode

func RegisterErrCode(pairs ...CodePair)

RegisterErrCode append custom error code

func ServerErrorInterceptor

func ServerErrorInterceptor(ctx context.Context, req interface{},
	info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error)

ServerErrorInterceptor transfer a error to status error

func ServiceErr2GRPCErr

func ServiceErr2GRPCErr(err error) error

ServiceErr2GRPCErr serviceErr covert to GRPCErr

Types

type Code

type Code = codes.Code
const (
	OK Code = iota
	Canceled
	Unknown
	InvalidArgument
	DeadlineExceeded
	NotFound
	AlreadyExists
	PermissionDenied
	ResourceExhausted
	FailedPrecondition
	Aborted
	OutOfRange
	Unimplemented
	Internal
	Unavailable
	DataLoss
	Unauthenticated
)

type CodePair

type CodePair struct {
	Code Code
	// Desc is the error brief description with upper case, like "CUSTOM_ERROR"
	Desc string
}

CodePair custom error code

type Error

type Error struct {
	Code Code
	Err  error
}

func NewServiceErr

func NewServiceErr(code Code, err error) *Error

func (*Error) Error

func (e *Error) Error() string

func (*Error) Format

func (e *Error) Format(s fmt.State, verb rune)

Jump to

Keyboard shortcuts

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