errorx

package
v0.1.11 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2023 License: MIT Imports: 3 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 {
	BizType  string `json:"biz_type"`
	Code     int    `json:"code"`
	Msg      string `json:"msg"`
	Metadata Metadata
	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) 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