Documentation
¶
Index ¶
- func Format(err error) string
- func HTTPStatus(kind Kind) int
- func IsPublic(err error) bool
- type AppError
- func Biz(code, msg string) *AppError
- func Forbidden(msg string) *AppError
- func Internal(msg string, err error) *AppError
- func New(kind Kind, code, msg string) *AppError
- func NotFound(msg string) *AppError
- func Unauthorized(msg string) *AppError
- func Validation(msg string) *AppError
- func Wrap(kind Kind, code, msg string, err error) *AppError
- type BizError
- type Kind
- type Kinded
- type PublicError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type AppError ¶ added in v1.1.0
AppError 是框架推荐的统一应用错误。
type BizError ¶
BizError 表示可直接展示给用户的业务错误(非系统内部错误)。 推荐新代码使用 AppError + KindBiz;BizError 保持兼容。
type Kind ¶ added in v1.1.0
type Kind string
Kind 描述错误类别,用于日志级别与 HTTP 映射。
const ( KindBiz Kind = "biz" // 可展示业务失败,默认 HTTP 200 KindValidation Kind = "validation" // 400 KindForbidden Kind = "forbidden" // 403 KindNotFound Kind = "not_found" // 404 KindConflict Kind = "conflict" // 409 KindTooManyRequests Kind = "rate_limited" // 429 KindInternal Kind = "internal" // 500,不对外暴露原文 )
type Kinded ¶ added in v1.1.0
Kinded 可查询错误类别(须同时是 error,以便 errors.AsType)。
Source Files
¶
- errors.go
- kind.go
Click to show internal directories.
Click to hide internal directories.