ex

package
v1.1.34 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BIZ     = 100000 // 普通业务异常
	GRPC    = 300000 // GRPC请求失败
	WS_WAIT = 999992 // WS等待响应超时
	WS_SEND = 999993 // WS发送数据失败
	JSON    = 999994 // JSON转换异常
	NUMBER  = 999995 // 数值转换异常
	DATA    = 999996 // 数据服务异常
	CACHE   = 999997 // 缓存服务异常
	SYSTEM  = 999998 // 系统级异常
	UNKNOWN = 999999 // 未知异常

	MQ                 = 800000 // MQ服务异常
	REDIS_LOCK_ACQUIRE = 800001 // redis锁获取失败
	REDIS_LOCK_PENDING = 800002 // redis锁正在处理
	REDIS_LOCK_TIMEOUT = 800003 // redis锁自旋超时
	REDIS_LOCK_RELEASE = 800004 // redis锁释放失败
	LOCAL_LOCK_ACQUIRE = 800005 // 本地锁获取失败
)
View Source
const (
	JSON_ERR    = "failed to respond to JSON data"
	GOB_ERR     = "failed to respond to GOB data"
	DATA_ERR    = "failed to loaded data service"
	DATA_C_ERR  = "failed to save data"
	DATA_R_ERR  = "failed to read data"
	DATA_U_ERR  = "failed to update data"
	DATA_D_ERR  = "failed to delete data"
	CACHE_ERR   = "failed to loaded cache service"
	CACHE_C_ERR = "failed to save cache data"
	CACHE_R_ERR = "failed to read cache data"
	CACHE_U_ERR = "failed to update cache data"
	CACHE_D_ERR = "failed to delete cache data"

	MQ_ERR      = "failed to loaded mq service"
	MQ_SEND_ERR = "failed to send mq data"
	MQ_REVD_ERR = "failed to receive mq data"
)

Variables

This section is empty.

Functions

func HTTPStatusCode added in v1.1.33

func HTTPStatusCode(code int) int

HTTPStatusCode 将 Throw.Code 映射为合法 HTTP status(100–999);业务码等非 HTTP 码回落 401。

func NormalizeCode added in v1.1.33

func NormalizeCode(code int) int

NormalizeCode 业务码缺省(0)时回落 BIZ,与 Throw.Error 一致。

func OutError

func OutError(title string, err error)

Types

type Throw

type Throw struct {
	// 24字节字段(slice)- 放在开头减少填充
	Arg []string // Additional arguments

	// 16字节字段(string)- 按对齐分组
	Msg    string // Error message
	Url    string // Related URL or endpoint
	ErrMsg string // Serialized error message (for error chain preservation)

	// 16字节字段(interface)- 与string对齐
	Err error `json:"-"` // Underlying error (not serialized)

	// 8字节字段(int)- 放在最后
	Code int // Error code
}

Throw represents a structured application error with additional context easyjson:json

func Catch

func Catch(err error) Throw

func Normalize added in v1.1.33

func Normalize(t Throw) Throw

Normalize 复制 Throw 并规范化 Code。

func (Throw) Error

func (self Throw) Error() string

func (Throw) MarshalEasyJSON

func (v Throw) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (Throw) MarshalJSON

func (v Throw) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*Throw) UnmarshalEasyJSON

func (v *Throw) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*Throw) UnmarshalJSON

func (v *Throw) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

Jump to

Keyboard shortcuts

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