errorx

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsNotFound added in v0.1.18

func IsNotFound(err error) bool

Types

type Error

type Error struct {
	BizType  string   `json:"biz_type"` // 业务类型
	Code     int      `json:"code"`     // 错误码
	Msg      string   `json:"msg"`      // 错误信息
	Metadata Metadata // 元数据
	IsShow   bool     // 是否需要展示给用户
	Err      error    // 原始错误
}

func BadRequest

func BadRequest(format string, args ...any) *Error

func Exist

func Exist(format string, args ...any) *Error

func From

func From(err error) *Error

func Internal

func Internal(err error, format string, args ...any) *Error

Internal 创建内部错误, 通常用于服务端内部错误, 如数据库, 缓存等

func New

func New(bizType string, code int, message string) *Error

New 创建自定义错误, 通常用于业务并没有err返回, 但是属于业务逻辑错误. 此时需要给前端一个友好提示 eg: New("user-service-Login", 404001, "用户不存在")

func NotFound

func NotFound(format string, args ...any) *Error

func Unauthorized

func Unauthorized(format string, args ...any) *Error

func (*Error) Error

func (e *Error) Error() string

func (*Error) Show added in v0.2.0

func (e *Error) Show() *Error

func (*Error) Unwrap

func (e *Error) Unwrap() error

func (*Error) WithError

func (e *Error) WithError(err error) *Error

func (*Error) WithMessage

func (e *Error) WithMessage(format string, args ...any) *Error

func (*Error) WithMetadata

func (e *Error) WithMetadata(metadata Metadata) *Error

type Metadata

type Metadata map[string]any

type ResCode

type ResCode int
const (
	CodeSuccess       ResCode = 200
	CodeInvalidParams ResCode = 400
	CodeUnauthorized  ResCode = 401
	CodeInvalidToken  ResCode = 403
	CodeInternalErr   ResCode = 500
)

func (ResCode) Msg

func (code ResCode) Msg() string

Jump to

Keyboard shortcuts

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