Documentation ¶ Index ¶ func ErrorHandlingInterceptor() grpc.UnaryServerInterceptor func FromError(err error) error func New(code ErrorCode, message string) error func ToError(err error) error func WithDetails(err error, details ...proto.Message) error type Error func (e *Error) Error() string type ErrorCode Constants ¶ This section is empty. Variables ¶ This section is empty. Functions ¶ func ErrorHandlingInterceptor ¶ func ErrorHandlingInterceptor() grpc.UnaryServerInterceptor func FromError ¶ func FromError(err error) error FromError 从普通错误转换为 gRPC 错误 func New ¶ func New(code ErrorCode, message string) error New 创建新的错误 func ToError ¶ func ToError(err error) error ToError 从 gRPC 错误转换为普通错误 func WithDetails ¶ func WithDetails(err error, details ...proto.Message) error WithDetails 添加错误详情 Types ¶ type Error ¶ type Error struct { Code ErrorCode Message string Details []proto.Message } Error 定义错误结构 func (*Error) Error ¶ func (e *Error) Error() string type ErrorCode ¶ type ErrorCode int32 ErrorCode 定义错误码类型 const ( // 系统级错误码 Unknown ErrorCode = 10000 Internal ErrorCode = 10001 InvalidArgument ErrorCode = 10002 NotFound ErrorCode = 10003 Unauthorized ErrorCode = 10004 Timeout ErrorCode = 10005 // 业务级错误码 (11000-19999) BusinessError ErrorCode = 11000 ) Source Files ¶ View all Source files errors.go Click to show internal directories. Click to hide internal directories.