errors

package
v0.0.0-...-b08fcc5 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2023 License: Apache-2.0 Imports: 8 Imported by: 10

Documentation

Index

Constants

View Source
const (
	Success            = 0
	BadRequest         = 9000
	VerificationFailed = 9001
	InternalServer     = 9002
	InvalidParam       = 9003

	NotLogin         = 9100
	NoPhoneBound     = 9101
	NoPermission     = 9102
	ActionFailed     = 9103
	AccountBanned    = 9104
	AliPayRequestErr = 9109

	UnKnown = 100000
)

Variables

View Source
var (
	ErrorMessages = make(map[int32]string)
	ID            int32
	Name          string
)
View Source
var (
	ErrorBadRequest         = new499Response(BadRequest, "请求发生错误")
	ErrorVerificationFailed = new499Response(VerificationFailed, "校验失败")
	ErrorInternalServer     = new500Response(InternalServer, "服务器内部错误")
	ErrorInvalidParam       = new499Response(InvalidParam, "请求参数不合法")

	ErrorNotLogin        = new499Response(NotLogin, "用户未登录")
	ErrorNoPhoneBound    = new499Response(NoPhoneBound, "用户未绑定手机号")
	ErrorNoPermission    = new499Response(NoPermission, "无权限操作")
	ErrorActionFailed    = new499Response(ActionFailed, "操作失败")
	ErrorBannedFailed    = new499Response(AccountBanned, "账号被封禁")
	ErrorCountryNotFound = new499Response(AccountBanned, "当前国家未知")
)

Functions

func As

func As(err error, target interface{}) bool

As finds the first error in err's chain that matches target, and if so, sets target to that error value and returns true.

The chain consists of err itself followed by the sequence of errors obtained by repeatedly calling Unwrap.

An error matches target if the error's concrete value is assignable to the value pointed to by target, or if the error has a method As(interface{}) bool such that As(target) returns true. In the latter case, the As method is responsible for setting target.

As will panic if target is not a non-nil pointer to either a type that implements error, or to any interface type. As returns false if err is nil.

func ConvertBusinessCode

func ConvertBusinessCode(err error) int

func Def

func Def(t ErrorType, code int32, message string) error

func ErrCustomData

func ErrCustomData(code int32, message string, args interface{}) error

func ErrCustomer

func ErrCustomer(message string) error

func Init

func Init(id int32, name string) error

func Is

func Is(err, target error) bool

Is reports whether any error in err's chain matches target.

The chain consists of err itself followed by the sequence of errors obtained by repeatedly calling Unwrap.

An error is considered to match a target if it is equal to that target or if it implements a method Is(error) bool such that Is(target) returns true.

func IsBadRequest

func IsBadRequest(err error) bool

IsBadRequest

func IsErrorCodeEqual

func IsErrorCodeEqual(err, target error) bool

IsErrorCodeEqual 判断错误码是否相等

func IsInternalServer

func IsInternalServer(err error) bool

IsInternalServer

func IsInvalidParam

func IsInvalidParam(err error) bool

IsInvalidParam

func Parse

func Parse(err error) *mErrors.Error

func RedisIsNil

func RedisIsNil(err error) bool

func Unwrap

func Unwrap(err error) error

Unwrap returns the result of calling the Unwrap method on err, if err's type contains an Unwrap method returning error. Otherwise, Unwrap returns nil.

Types

type ErrorType

type ErrorType int32
var (
	LogicError     ErrorType = 1 // 代码逻辑错误
	DBError        ErrorType = 2 // 数据库错误,mysql/redis
	ThirdPartError ErrorType = 3 // 调用第三方服务出错
)

type FieldErrors

type FieldErrors []fieldError

func (*FieldErrors) Add

func (e *FieldErrors) Add(resource string, filed string, msg ...string)

func (*FieldErrors) Copy

func (e *FieldErrors) Copy(item validator.FieldError)

func (*FieldErrors) Error

func (e *FieldErrors) Error() string

type ValidateError

type ValidateError struct {
	Code    int
	Message string
	Errors  FieldErrors
}

Validate Error

func NewValidateError

func NewValidateError(code int, message string, err error) *ValidateError

func (*ValidateError) Error

func (e *ValidateError) Error() string

Jump to

Keyboard shortcuts

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