errs

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2023 License: BSD-3-Clause Imports: 6 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CodeToError added in v0.2.18

func CodeToError(c codes.Code) string

CodeToError

func CodeToStatus added in v0.2.18

func CodeToStatus(code codes.Code) int

CodeToStatus

func New

func New(code codes.Code, msg string) error

New 创建一个error,默认为业务错误类型,提高业务开发效率

func Newf

func Newf(code codes.Code, format string, params ...interface{}) error

Newf 创建一个error,默认为业务错误类型,msg支持格式化字符串

func RegisterErrorCodes added in v0.2.18

func RegisterErrorCodes(codeErrors map[int32]string)

RegisterErrorCodes set custom error codes for DefaultHTTPError for exp: server.RegisterErrorCodes(pb.ErrorCode_name) SetCustomErrorCodes set custom error codes for DefaultHTTPError the map[int32]string is compact to protobuf's ENMU_name 2*** HTTP status 200 4*** HTTP status 400 5*** AND other HTTP status 500 For exp: in proto

enum CommonError {
	captcha_required = 4001;
	invalid_captcha = 4002;
}

in code server.RegisterErrorCodes(common.CommonError_name)

Types

type CatchHandler

type CatchHandler interface {
	Catch(e error, handler func(err error)) CatchHandler
	CatchAll(handler func(err error)) FinalHandler
	FinalHandler
}

func Try

func Try(f func()) CatchHandler

type FinalHandler

type FinalHandler interface {
	Finally(handlers ...func())
}

Jump to

Keyboard shortcuts

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