codes

package
v0.0.0-alpha Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2023 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CodeOk                             = 0
	CodeUnknown                        = 1
	CodeNullPointer                    = 2
	CodeNullObject                     = 3
	CodeInvalidSdkToken                = 4
	CodeInvalidArgs                    = 5
	CodeInvalidJwt                     = -20
	CodeJwtExpire                      = 7
	CodeTODO                           = 8
	CodeInvalidPassword                = 9
	CodePayOrderStatusInvalid          = 10
	CodeAccountPlatformNotSupport      = 11
	CodePayOrderAccountPlatformInvalid = 12
	CodePayOrderAmountInvalid          = 13
	CodeMax                            = 255
)

错误码常量 1-255 系统预留

Variables

View Source
var (
	ErrOk                             = New(CodeOk, msg_Ok)
	ErrUnknown                        = New(CodeUnknown, msg_Unknown)
	ErrNullObject                     = New(CodeNullObject, msg_NullObject)
	ErrInvalidSdkToken                = New(CodeInvalidSdkToken, msg_InvalidSdkToken)
	ErrInvalidArgs                    = New(CodeInvalidArgs, msg_InvalidArgs)
	ErrInvalidJwt                     = New(CodeInvalidJwt, msg_InvalidJwt)
	ErrJwtExpire                      = New(CodeJwtExpire, msg_JwtExpire)
	ErrTODO                           = New(CodeTODO, msg_TODO)
	ErrInvalidPassword                = New(CodeInvalidPassword, msg_InvalidPassword)
	ErrPayOrderStatusInvalid          = New(CodePayOrderStatusInvalid, msg_PayOrderStatusInvalid)
	ErrAccountPlatformNotSupport      = New(CodeAccountPlatformNotSupport, msg_AccountPlatformNotSupport)
	ErrPayOrderAccountPlatformInvalid = New(CodePayOrderAccountPlatformInvalid, msg_PayOrderAccountPlatformInvalid)
	ErrPayOrderAmountInvalid          = New(CodePayOrderAmountInvalid, msg_PayOrderAmountInvalid)
)

Functions

func Code

func Code(err error) int32

提取错误码

func Is

func Is(err error, target error) bool

from pkg "golang.org/x/xerrors"

func Msg

func Msg(err error) string

提取错误描述

func SetLogger

func SetLogger(l Logger)

func Stacktrace

func Stacktrace(err error) string

提取调用栈

func Unwrap

func Unwrap(err error) error

Types

type CodeError

type CodeError struct {
	Code   int32
	Msg    string
	Values map[string]interface{}
}

func New

func New(code int32, msg string, values ...interface{}) *CodeError

创建error_code

func (*CodeError) Error

func (e *CodeError) Error() string

格式化错误字符串

func (*CodeError) Is

func (e *CodeError) Is(err error) bool

func (*CodeError) Trace

func (e *CodeError) Trace(values ...interface{}) *TraceError

拷贝error并且附加stack

func (*CodeError) TraceWithSkip

func (e *CodeError) TraceWithSkip(skip int, values ...interface{}) *TraceError

type Logger

type Logger interface {
	Error(...interface{})
}

type TraceError

type TraceError struct {
	// contains filtered or unexported fields
}

跟踪错误信息

func Trace

func Trace(err error, values ...interface{}) *TraceError

wrap error

func TraceErrTODO

func TraceErrTODO(values ...interface{}) *TraceError

TODO错误

func (*TraceError) Error

func (e *TraceError) Error() string

func (*TraceError) Is

func (e *TraceError) Is(err error) bool

func (*TraceError) Print

func (e *TraceError) Print()

func (*TraceError) Unwrap

func (e *TraceError) Unwrap() error

Jump to

Keyboard shortcuts

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