errors

package
v3.0.0-...-4803698 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Error

type Error struct {
	Code    uint16 `msg:"c"`          // 错误码 (用于程序逻辑判断,如 1001=UserNotFound)
	Msg     string `msg:"m"`          // 错误信息 (用于日志和人类阅读)
	Data    []byte `msg:"d,allownil"` // (可选) 附加数据,例如具体的校验失败字段
	TraceID string `msg:"t"`          // (可选) 分布式追踪 ID
}

所有错误,由这个接口包装,以便以msgp序列化,然后传递

func New

func New(code T, msg string) *Error

func Newf

func Newf(code T, msg string, args ...any) *Error

func (*Error) DecodeMsg

func (z *Error) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable

func (*Error) EncodeMsg

func (z *Error) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (*Error) Error

func (e *Error) Error() string

func (*Error) MarshalMsg

func (z *Error) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (*Error) Msgsize

func (z *Error) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*Error) UnmarshalMsg

func (z *Error) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

func (*Error) WithData

func (e *Error) WithData(data []byte) *Error

func (*Error) WithTraceID

func (e *Error) WithTraceID(traceID string) *Error

type T

type T = uint16
const (
	ClientInternal         T = 400 //参数错误
	ClientUnauthorized     T = 401 //未授权
	ClientInvalidArgs      T = 402 //参数错误
	CodeClientForbidden    T = 403 //禁止访问
	ClientNotFound         T = 404 //找不到
	ClientMethodNotAllowed T = 405 //方法禁用
	ClientCallError        T = 406 //方法禁用
	ClientReturnInvalid    T = 407 //返回类型错误
	ClientTooManyRequests  T = 429 //请求过多
	ClientSendChanExhaust  T = 497 //请求队列已经耗尽
	ClientCanceled         T = 498 //请求取消
	ClientStandardError    T = 499 //客户端标准错误
)

client

const (
	ServerInternal           T = 500 //服务器内部错误
	ServerServiceUnavailable T = 503 //服务不可用
	ServerDeadlineExceeded   T = 504 //网关超时
	ServerServiceNotFound    T = 505 //服务未找到
	ServerStandardError      T = 599 //服务器标准错误
)

server

const (
	RemoteInternal      T = 600 //远程内部错误
	RemoteTimeout       T = 601 //远程超时错误
	RemoteStandardError T = 699 //远程标准错误
)

remote

const None T = 0

是一个假错误,不是真的错误,既没有返回值,也没有错误,需要,就是作为特殊功能的返回.eg:重置客户端的EOS 如果表示为空的返回值,就需要一个接受的值,但是没有内定的接受。Error是固定的,所以用这个不是错误的错误表示没有返回值

Jump to

Keyboard shortcuts

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