reason

package
v1.5.2 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrBadRequest           = NewError("ErrBadRequest", "请求参数有误")
	ErrDB                   = NewError("ErrStore", "数据发生错误")
	ErrServer               = NewError("ErrServer", "服务器发生错误")
	ErrUnauthorizedToken    = NewError("ErrUnauthorizedToken", "用户已过期或错误").SetHTTPStatus(401)
	ErrJSON                 = NewError("ErrJSON", "JSON 编解码出错")
	ErrNotFound             = NewError("ErrNotFound", "资源未找到")
	ErrUsedLogic            = NewError("ErrUsedLogic", "使用逻辑错误")
	ErrLoginLimiter         = NewError("ErrLoginLimiter", "触发登录限制")
	ErrPermissionDenied     = NewError("ErrPermissionDenied", "没有该资源的权限")
	ErrTimeout              = NewError("ErrTimeout", "请求超时")
	ErrTooManyRequests      = NewError("ErrTooManyRequests", "请求频率过高")
	ErrServiceUnavailable   = NewError("ErrServiceUnavailable", "服务暂时不可用")
	ErrNetworkError         = NewError("ErrNetworkError", "网络连接错误")
	ErrFileUpload           = NewError("ErrFileUpload", "文件上传失败")
	ErrFileTooLarge         = NewError("ErrFileTooLarge", "文件大小超出限制")
	ErrUnsupportedMediaType = NewError("ErrUnsupportedMediaType", "不支持的媒体类型")
	ErrContentTooLarge      = NewError("ErrContentTooLarge", "请求体过大")

	ErrRateLimit = NewError("ErrRateLimit", "请求频率过高").SetHTTPStatus(429)
)

常用错误

View Source
var (
	ErrNameOrPasswd    = NewError("ErrNameOrPasswd", "用户名或密码错误")
	ErrCaptchaWrong    = NewError("ErrCaptchaWrong", "验证码错误")
	ErrAccountDisabled = NewError("ErrAccountDisabled", "登录限制")
)

业务错误

Functions

func IsCustomError added in v1.3.4

func IsCustomError(err error) bool

IsCustomError 是否自定义的错误 需要断言后的类型,建议直接使用 `err.(CustomError)` 语法

Types

type CustomError

type CustomError interface {
	error
	ErrorInfoer
	With(args ...string) CustomError
	Withf(format string, args ...any) CustomError
	SetMsg(s string) CustomError
	SetHTTPStatus(status int) CustomError
}

func NewError

func NewError(reason, msg string) CustomError

NewError ..

type Error

type Error struct {
	Reason     string   `json:"reason"`
	Msg        string   `json:"msg"`
	Details    []string `json:"details"`
	HTTPStatus int      `json:"-"`
}

func (*Error) As

func (e *Error) As(target any) bool

func (*Error) Error

func (e *Error) Error() string

Error implements CustomError.

func (*Error) GetDetails

func (e *Error) GetDetails() []string

GetDetails implements CustomError.

func (*Error) GetHTTPCode

func (e *Error) GetHTTPCode() int

GetHTTPCode implements CustomError.

func (*Error) GetMessage

func (e *Error) GetMessage() string

GetMessage implements CustomError.

func (*Error) GetReason

func (e *Error) GetReason() string

GetReason implements CustomError.

func (*Error) Is

func (e *Error) Is(err error) bool

func (*Error) SetHTTPStatus

func (e *Error) SetHTTPStatus(status int) CustomError

SetHTTPStatus implements CustomError.

func (*Error) SetMsg

func (e *Error) SetMsg(s string) CustomError

SetMsg implements CustomError.

func (*Error) With

func (e *Error) With(args ...string) CustomError

With implements CustomError.

func (*Error) Withf

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

Withf implements CustomError.

type ErrorInfoer

type ErrorInfoer interface {
	GetReason() string
	GetHTTPCode() int
	GetMessage() string
	GetDetails() []string
}

Jump to

Keyboard shortcuts

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