errno

package
v0.0.0-...-b283e90 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

This file is designed to define any error code

Index

Constants

View Source
const (
	// For microservices
	SuccessCode = 10000
	SuccessMsg  = "ok"

	// Error
	/*
		200xx: 参数错误,Param 打头
		300xx: 鉴权错误,Auth 打头
		400xx: 业务错误,Biz 打头
		500xx: 内部错误,Internal 打头
	*/
	ParamErrorCode         = 20001 // 参数错误
	ParamEmptyCode         = 20002 // 参数为空
	ParamMissingHeaderCode = 20003 // 缺少请求头数据(id or cookies)
	ParamInvalidCode       = 20004 // 参数无效
	ParamMissingCode       = 20005 // 参数缺失
	ParamTooLongCode       = 20006 // 参数过长
	ParamTooShortCode      = 20007 // 参数过短
	ParamTypeCode          = 20008 // 参数类型错误
	ParamFormatCode        = 20009 // 参数格式错误
	ParamRangeCode         = 20010 // 参数范围错误
	ParamValueCode         = 20011 // 参数值错误
	ParamFileNotExistCode  = 20012 // 文件不存在
	ParamFileReadErrorCode = 20013 // 文件读取错误

	AuthErrorCode          = 30001 // 鉴权错误
	AuthInvalidCode        = 30002 // 鉴权无效
	AuthAccessExpiredCode  = 30003 // 访问令牌过期
	AuthRefreshExpiredCode = 30004 // 刷新令牌过期
	AuthMissingCode        = 30005 // 鉴权缺失

	BizErrorCode               = 40001 // 业务错误
	BizLogicCode               = 40002 // 业务逻辑错误
	BizLimitCode               = 40003 // 业务限制错误
	BizNotExist                = 40005 // 业务不存在错误
	BizFileUploadErrorCode     = 40006 // 文件上传错误(service 层)
	BizJwchCookieExceptionCode = 40007 // jwch cookie异常

	InternalServiceErrorCode   = 50001 // 未知服务错误
	InternalDatabaseErrorCode  = 50002 // 数据库错误
	InternalRedisErrorCode     = 50003 // Redis错误
	InternalNetworkErrorCode   = 50004 // 网络错误
	InternalTimeoutErrorCode   = 50005 // 超时错误
	InternalIOErrorCode        = 50006 // IO错误
	InternalJSONErrorCode      = 50007 // JSON错误
	InternalXMLErrorCode       = 50008 // XML错误
	InternalURLEncodeErrorCode = 50009 // URL编码错误
	InternalHTTPErrorCode      = 50010 // HTTP错误
	InternalHTTP2ErrorCode     = 50011 // HTTP2错误
	InternalGRPCErrorCode      = 50012 // GRPC错误
	InternalThriftErrorCode    = 50013 // Thrift错误
	InternalProtobufErrorCode  = 50014 // Protobuf错误
	InternalSQLErrorCode       = 50015 // SQL错误
	InternalNoSQLErrorCode     = 50016 // NoSQL错误
	InternalORMErrorCode       = 50017 // ORM错误
	InternalQueueErrorCode     = 50018 // 队列错误
	InternalETCDErrorCode      = 50019 // ETCD错误
	InternalTraceErrorCode     = 50020 // Trace错误

	// SuccessCodePaper paper在旧版Android中的SuccessCode是2000,用作兼容
	SuccessCodePaper = 2000
)

Variables

View Source
var (
	Success                   = NewErrNo(SuccessCode, "ok")
	CustomLaunchScreenSuccess = NewErrNo(consts.StatusOK, "ok") // 兼容处理

	AuthError          = NewErrNo(AuthErrorCode, "鉴权失败")            // 鉴权失败,通常是内部错误,如解析失败
	AuthInvalid        = NewErrNo(AuthInvalidCode, "鉴权无效")          // 鉴权无效,如令牌颁发者不是 west2-online
	AuthAccessExpired  = NewErrNo(AuthAccessExpiredCode, "访问令牌过期")  // 访问令牌过期
	AuthRefreshExpired = NewErrNo(AuthRefreshExpiredCode, "刷新令牌过期") // 刷新令牌过期
	AuthMissing        = NewErrNo(AuthMissingCode, "鉴权缺失")          // 鉴权缺失,如访问令牌缺失

	ParamError         = NewErrNo(ParamErrorCode, "参数错误") // 参数校验失败,可能是参数为空、参数类型错误等
	ParamMissingHeader = NewErrNo(ParamMissingHeaderCode, "缺失合法学生请求头数据")

	BizError             = NewErrNo(BizErrorCode, "请求业务出现问题")
	InternalServiceError = NewErrNo(InternalServiceErrorCode, "内部服务错误")

	SuffixError           = NewErrNo(ParamErrorCode, "文件不可用")
	NoRunningPictureError = NewErrNo(BizErrorCode, "没有可用图片")
	NoMatchingPlanError   = NewErrNo(BizErrorCode, "没有匹配的计划")

	// internal error
	UpcloudError = NewErrNo(BizFileUploadErrorCode, "云服务商交互错误")

	// redis
	RedisError = NewErrNo(InternalRedisErrorCode, "缓存服务出现问题")
)

Functions

This section is empty.

Types

type ErrNo

type ErrNo struct {
	ErrorCode int64
	ErrorMsg  string
	// contains filtered or unexported fields
}

func ConvertErr

func ConvertErr(err error) ErrNo

ConvertErr convert error to ErrNo in Default user ServiceErrorCode

func Errorf

func Errorf(code int64, template string, args ...interface{}) ErrNo

func NewErrNo

func NewErrNo(code int64, msg string) ErrNo

func NewErrNoWithStack

func NewErrNoWithStack(code int64, msg string) ErrNo

func (ErrNo) Error

func (e ErrNo) Error() string

func (ErrNo) Format

func (e ErrNo) Format(st fmt.State, verb rune)

func (ErrNo) StackTrace

func (e ErrNo) StackTrace() any

func (ErrNo) WithError

func (e ErrNo) WithError(err error) ErrNo

WithError will add error msg after Message

func (ErrNo) WithMessage

func (e ErrNo) WithMessage(msg string) ErrNo

WithMessage will replace default msg to new

type Frame

type Frame uintptr

Frame represents a program counter inside a stack frame. For historical reasons if Frame is interpreted as a uintptr its value represents the program counter + 1.

func (Frame) Format

func (f Frame) Format(s fmt.State, verb rune)

Format formats the frame according to the fmt.Formatter interface.

%s    source file
%d    source line
%n    function name
%v    equivalent to %s:%d

Format accepts flags that alter the printing of some verbs, as follows:

%+s   function name and path of source file relative to the compile time
      GOPATH separated by \n\t (<funcname>\n\t<path>)
%+v   equivalent to %+s:%d

func (Frame) MarshalText

func (f Frame) MarshalText() ([]byte, error)

MarshalText formats a stacktrace Frame as a text string. The output is the same as that of fmt.Sprintf("%+v", f), but without newlines or tabs.

type StackTrace

type StackTrace []Frame

StackTrace is stack of Frames from innermost (newest) to outermost (oldest).

func (StackTrace) Format

func (st StackTrace) Format(s fmt.State, verb rune)

Format formats the stack of Frames according to the fmt.Formatter interface.

%v	lists the source file and line number for each Frame in the stack

Format accepts flags that alter the printing of some verbs, as follows:

%+v   Prints filename, function, and line number for each Frame in the stack.

Jump to

Keyboard shortcuts

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