package
Version:
v1.8.0
Opens a new window with list of versions in this module.
Published: Aug 15, 2026
License: MIT
Opens a new window with license information.
Imports: 3
Opens a new window with list of imports.
Imported by: 0
Opens a new window with list of known importers.
Documentation
¶
Package apperr 定义统一业务错误:HTTP 状态 + 业务码 + 消息 + 原始错误链。
与 webiris.OK/Fail 配合,业务代码返回 apperr.Error,由中间件统一转响应。
Code 是业务错误码。
const (
CodeOK Code = 0
CodeBadRequest Code = 400
CodeUnauthorized Code = 401
CodeForbidden Code = 403
CodeNotFound Code = 404
CodeInternal Code = 500
)
常用业务错误码(与 HTTP 状态一致,便于调试;业务可自定义扩展码)。
Error 是统一业务错误。
Message 会直接暴露给调用方,不得包含敏感信息;原始错误通过 Cause 保留在服务端日志。
From 把任意 error 转换为 *Error:
已是 *Error 时原样返回;其他错误转换为 500 内部错误(服务端应记录 Cause)。
Wrap 包装原始错误为业务错误;原始错误不出现在 Message 中。
Unwrap 支持 errors.Is/As 定位原始错误。
Source Files
¶
Click to show internal directories.
Click to hide internal directories.