xerror

package
v0.0.0-...-a89d410 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UnknownCode = 2
)

Variables

View Source
var (
	OK                 = New(0, "请求正常")
	Canceled           = New(1, "操作取消")
	Unknown            = New(2, "未知错误")
	InvalidArgument    = New(3, "无效参数")
	DeadlineExceeded   = New(4, "处理时间超过最后期限")
	NotFound           = New(5, "访问链接不存在")
	AlreadyExists      = New(6, "目标已存在")
	PermissionDenied   = New(7, "权限不足")
	ResourceExhausted  = New(8, "资源耗尽")
	FailedPrecondition = New(9, "前置条件出错")
	Aborted            = New(10, "操作中途失败")
	OutOfRange         = New(11, "操作超出有效范围")
	Unimplemented      = New(12, "当前服务未实现")
	Internal           = New(13, "服务内部异常")
	Unavailable        = New(14, "服务当前不可用")
	DataLoss           = New(15, "数据丢失")
	Unauthenticated    = New(16, "未授权错误")
)

Functions

func ErrsFromGRPCCode

func ErrsFromGRPCCode(code codes.Code) int32

StatusFromGRPCCode converts a gRPC error code into the corresponding Err code.

func GRPCCodeFromeErrs

func GRPCCodeFromeErrs(code int32) codes.Code

GRPCCodeFromStatus converts an Err code into the corresponding gRPC response status.

Types

type Err

type Err struct {
	Ecode int32       `json:"error"`
	Msg   string      `json:"msg"`
	Data  interface{} `json:"data"`
}

Err struct

func Convert

func Convert(err error) *Err

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

func New

func New(code codes.Code, message string) *Err

New returns an error object for the code, message.

func (*Err) Error

func (e *Err) Error() string

Error implements the error interface.

func (*Err) GRPCStatus

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

GRPCStatus returns the Status represented by se.

func (*Err) GetData

func (e *Err) GetData() interface{}

GetData return the Data

func (*Err) GetEcode

func (e *Err) GetEcode() int32

GetEcode return the packaged Ecode

func (*Err) GetMsg

func (e *Err) GetMsg() string

GetMsg return the Msg

func (*Err) WithData

func (e *Err) WithData(data interface{}) *Err

WithData allows the programmer to override Data and ruturn the new Err

func (*Err) WithMsg

func (e *Err) WithMsg(msg string) *Err

WithMsg allows the programmer to override Msg and ruturn the new Err

Jump to

Keyboard shortcuts

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