errors

package
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: May 31, 2023 License: Apache-2.0 Imports: 3 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NotLoginError = twirp.NewError(twirp.Unauthenticated, "must login")

NotLoginError 错误未登录

View Source
var PermissionDeniedError = twirp.NewError(twirp.PermissionDenied, "permission denied")

PermissionDeniedError 权限不够

View Source
var TokenExpired error = twirp.NewError(twirp.DeadlineExceeded, "Token is expired")

token过期

View Source
var TokenInvalid error = twirp.NewError(twirp.InvalidArgument, "Couldn't handle this token:")

无法处理token

View Source
var TokenMalformed error = twirp.NewError(twirp.InvalidArgument, "That's not even a token")

不是token

View Source
var TokenNotValidYet error = twirp.NewError(twirp.InvalidArgument, "Token not active yet")

token未激活

Functions

func Cause

func Cause(err error) error

Cause 获取原始错误对象

func Code

func Code(err error) (int32, bool)

Code 提取错误码,codeError 返回 code 和 true,其他返回 0 和 false

func CodeError

func CodeError(code int32, err string) error

CodeError 新建业务错误,附带错误码

func Errorf

func Errorf(format string, args ...interface{}) error

Errorf 创建新错误

func InvalidArgumentError

func InvalidArgumentError(argument string, validationMsg string) error

InvalidArgumentError 参数错误,400

func MetaError added in v1.3.6

func MetaError(code int32, err string) twirp.Error

MetaError 新建meta错误

为了避免与httpStatus错误冲突,错误码及错误信息将放在meta中。 返回 httpStatus 为 200。 返回案例如下:

{
   "code": "",
   "msg": "",
   "meta": {
       "code": "@code",
       "msg": "@err"
   }
}

func Wrap

func Wrap(err error, args ...interface{}) error

Wrap 包装错误信息,附加调用栈 第二个参数只能是 string,也可以不传,大部分情况不用传

Types

This section is empty.

Jump to

Keyboard shortcuts

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