pyerrors

package
v0.0.0-...-f274578 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2022 License: MIT Imports: 5 Imported by: 1

README

pyerrors

提供项目中全局错误(错误码)的封装

  • redis:错误码-10000~-19999
  • kafka:错误码-20000~-29999
  • go-workqueue组件:错误码-30000~-39999

Documentation

Index

Constants

View Source
const (
	//Nil reply returned by Redis when key does not exist.
	RedisNil = redis.Nil
)

Variables

View Source
var (
	OK = _add(0) // 正确

	NotModified        = _add(-304) // 木有改动
	TemporaryRedirect  = _add(-307) // 302跳转
	RequestErr         = _add(-400) // 请求错误
	Unauthorized       = _add(-401) // 未认证
	AccessDenied       = _add(-403) // 访问权限不足
	NothingFound       = _add(-404) // 啥都木有
	MethodNotAllowed   = _add(-405) // 不支持该方法
	Conflict           = _add(-409) // 冲突
	Canceled           = _add(-498) // 客户端取消请求
	ServerErr          = _add(-500) // 服务器错误
	ServiceUnavailable = _add(-503) // 过载保护,服务暂不可用(客户端熔断返回此错误)
	Deadline           = _add(-504) // 服务调用超时
	LimitExceed        = _add(-509) // 超出限制             (服务端限流返回此错误)

)

全局错误码,可以被外部引用!NotModified/TemporaryRedirect...

View Source
var (
	// ErrInvalidParams  is returned when parameters is invalid.
	ErrRedisInvalidParams = _addWithMsg(-10002, "invalid params")

	// ErrNotObtained is returned when a Lock cannot be obtained.
	ErrRedisNotObtained = _addWithMsg(-10003, "redislock: not obtained")

	// ErrLockNotHeld is returned when trying to release an inactive Lock.
	ErrRedisLockNotHeld = _addWithMsg(-10004, "redislock: lock not held")
)
View Source
var (
	ErrWorkQueHandlerExists = _addWithMsg(-30001, "worker handler already registed")

	ErrWorkQueDriverExists = _addWithMsg(-30002, "driver already registed")

	ErrWorkQueBadDriver = _addWithMsg(-30003, "bad driver")

	ErrWorkQueBadDriverConfig = _addWithMsg(-30004, "bad driver config")
)
View Source
var (
	ErrRedisSample = _addWithMsg(-10001, "go-redis test error msg")
)

业务全局错误码

Functions

func Equal

func Equal(a, b Codes) bool

Equal equal a and b by code int.

func EqualError

func EqualError(code Codes, err error) bool

EqualError equal error

func Register

func Register(cm map[int]string)

Register register ecode message map.

Types

type Code

type Code int

Code 是 Codes实例化类型,本项目的错误码就是int,因为Codes实现了Error()方法,所以可以直接当做error返回 A Code is an int error code spec.

func Int

func Int(i int) Code

Int parse code int to error.

func New

func New(e int) Code

New new a ecode.Codes by int value. NOTE: ecode must unique in global, the New will check repeat and then panic.

func String

func String(e string) Code

String parse code string to error.

func (Code) Code

func (e Code) Code() int

Code return error code

func (Code) Details

func (e Code) Details() []interface{}

Details return details.

func (Code) Error

func (e Code) Error() string

func (Code) Message

func (e Code) Message() string

Message return error message

type Codes

type Codes interface {
	// sometimes Error return Code in string form
	// NOTE: don't use Error in monitor report even it also work for now
	Error() string
	// Code get error code.
	Code() int
	// Message get code message.
	Message() string
	//Detail get error detail,it may be nil.
	Details() []interface{}
}

Codes ecode error interface which has a code & message.

func Cause

func Cause(e error) Codes

Cause 方法:将error类型转换为项目Codes,生成错误必须调用errors包提供的方法生成!

Jump to

Keyboard shortcuts

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