errors

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

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
)

Jump to

Keyboard shortcuts

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