Documentation
¶
Index ¶
- Constants
- Variables
- func Err(c *gin.Context, err error)
- func ErrorHandlerMiddleware() gin.HandlerFunc
- func FormatErrorChain(err error) string
- func GetCode(err error) int
- func GetErrorDetails(err error) (errType string, message string, code int, requestID string)
- func GetType(err error) string
- func HasCause(err error, cause error) bool
- func Is(err error, errType string) bool
- func IsNil(err error) bool
- func IsNotNil(err error) bool
- func IsType(err error, errType string) bool
- func JoinErrors(errs ...error) error
- func RecoveryMiddleware() gin.HandlerFunc
- func RootCause(err error) error
- func WrapIfErr(err error, errType, message string, code int) error
- type AppError
- func AsAppError(err error) (*AppError, bool)
- func Config(message string, cause error) *AppError
- func ConfigInvalid(field string, cause error) *AppError
- func ConfigMissing(field string) *AppError
- func DBConnectionFailed(cause error) *AppError
- func DBQueryFailed(operation string, cause error) *AppError
- func DBRecordNotFound(resource string) *AppError
- func Database(message string, cause error) *AppError
- func DecryptCreateCipherFailed(cause error) *AppError
- func DecryptDecodeKeyFailed(cause error) *AppError
- func DecryptIncompleteRead(cause error) *AppError
- func DecryptInvalidKey(cause error) *AppError
- func DecryptOpenFileFailed(path string, cause error) *AppError
- func DecryptOperationCanceled() *AppError
- func DecryptReadFileFailed(path string, cause error) *AppError
- func DecryptWriteOutputFailed(cause error) *AppError
- func ErrInvalidArg(param string) *AppError
- func FileNotFound(path string) *AppError
- func FileReadFailed(path string, cause error) *AppError
- func FileWriteFailed(path string, cause error) *AppError
- func Forbidden(message string, cause error) *AppError
- func HTTP(message string, cause error) *AppError
- func Internal(message string, cause error) *AppError
- func InvalidParam(param string, reason string) *AppError
- func New(errType, message string, cause error, code int) *AppError
- func NotFound(resource string, cause error) *AppError
- func PlatformUnsupported(platform string, version int) *AppError
- func RateLimit(message string, cause error) *AppError
- func RequiredParam(param string) *AppError
- func Unauthorized(message string, cause error) *AppError
- func Validation(message string, cause error) *AppError
- func WeChat(message string, cause error) *AppError
- func WeChatAccountNotSelected() *AppError
- func WeChatDecryptFailed(cause error) *AppError
- func WeChatKeyExtractFailed(cause error) *AppError
- func WeChatProcessNotFound() *AppError
- func Wrap(err error, errType, message string, code int) *AppError
Constants ¶
const ( ErrTypeDatabase = "database" ErrTypeWeChat = "wechat" ErrTypeHTTP = "http" ErrTypeConfig = "config" ErrTypeInvalidArg = "invalid_argument" ErrTypeAuth = "authentication" ErrTypePermission = "permission" ErrTypeNotFound = "not_found" ErrTypeValidation = "validation" ErrTypeRateLimit = "rate_limit" ErrTypeInternal = "internal" )
定义错误类型常量
Variables ¶
var ErrAlreadyDecrypted = New(ErrTypeWeChat, "database file is already decrypted", nil, http.StatusBadRequest)
var ErrDecryptHashVerificationFailed = New(ErrTypeWeChat, "hash verification failed during decryption", nil, http.StatusBadRequest)
var ErrDecryptIncorrectKey = New(ErrTypeWeChat, "incorrect decryption key", nil, http.StatusBadRequest)
Functions ¶
func ErrorHandlerMiddleware ¶ added in v0.0.2
func ErrorHandlerMiddleware() gin.HandlerFunc
ErrorHandlerMiddleware 是一个 Gin 中间件,用于统一处理请求过程中的错误 它会为每个请求生成一个唯一的请求 ID,并在错误发生时将其添加到错误响应中
func FormatErrorChain ¶ added in v0.0.2
FormatErrorChain 格式化错误链,便于调试
func GetErrorDetails ¶ added in v0.0.2
GetErrorDetails 返回错误的详细信息,包括类型、消息、HTTP状态码和请求ID
func JoinErrors ¶ added in v0.0.2
JoinErrors 将多个错误合并为一个错误 如果只有一个错误不为 nil,则返回该错误 如果有多个错误不为 nil,则创建一个包含所有错误信息的新错误
func RecoveryMiddleware ¶ added in v0.0.2
func RecoveryMiddleware() gin.HandlerFunc
RecoveryMiddleware 是一个 Gin 中间件,用于从 panic 恢复并返回 500 错误
Types ¶
type AppError ¶
type AppError struct {
Type string `json:"type"` // 错误类型
Message string `json:"message"` // 错误消息
Cause error `json:"-"` // 原始错误
Code int `json:"-"` // HTTP Code
Stack []string `json:"-"` // 错误堆栈
RequestID string `json:"request_id,omitempty"` // 请求ID,用于跟踪
}
AppError 表示应用程序错误
func AsAppError ¶ added in v0.0.2
AsAppError 将错误转换为 AppError 类型
func ConfigInvalid ¶ added in v0.0.2
ConfigInvalid 创建配置无效错误
func ConfigMissing ¶ added in v0.0.2
ConfigMissing 创建配置缺失错误
func DBConnectionFailed ¶ added in v0.0.2
DBConnectionFailed 创建数据库连接失败错误
func DBQueryFailed ¶ added in v0.0.2
DBQueryFailed 创建数据库查询失败错误
func DBRecordNotFound ¶ added in v0.0.2
DBRecordNotFound 创建数据库记录未找到错误
func DecryptCreateCipherFailed ¶ added in v0.0.2
DecryptCreateCipherFailed 创建无法创建加密器错误
func DecryptDecodeKeyFailed ¶ added in v0.0.2
DecryptDecodeKeyFailed 创建无法解码十六进制密钥错误
func DecryptIncompleteRead ¶ added in v0.0.2
DecryptIncompleteRead 创建不完整的头部读取错误
func DecryptInvalidKey ¶ added in v0.0.2
DecryptInvalidKey 创建无效密钥格式错误
func DecryptOpenFileFailed ¶ added in v0.0.2
DecryptOpenFileFailed 创建无法打开数据库文件错误
func DecryptOperationCanceled ¶ added in v0.0.2
func DecryptOperationCanceled() *AppError
DecryptOperationCanceled 创建解密操作被取消错误
func DecryptReadFileFailed ¶ added in v0.0.2
DecryptReadFileFailed 创建无法读取数据库文件错误
func DecryptWriteOutputFailed ¶ added in v0.0.2
DecryptWriteOutputFailed 创建无法写入输出错误
func FileReadFailed ¶ added in v0.0.2
FileReadFailed 创建文件读取失败错误
func FileWriteFailed ¶ added in v0.0.2
FileWriteFailed 创建文件写入失败错误
func InvalidParam ¶ added in v0.0.2
InvalidParam 创建参数无效错误
func PlatformUnsupported ¶ added in v0.0.2
PlatformUnsupported 创建不支持的平台错误
func RequiredParam ¶ added in v0.0.2
RequiredParam 创建必需参数缺失错误
func Unauthorized ¶ added in v0.0.2
Unauthorized 创建未授权错误
func Validation ¶ added in v0.0.2
Validation 创建数据验证错误
func WeChatAccountNotSelected ¶ added in v0.0.2
func WeChatAccountNotSelected() *AppError
WeChatAccountNotSelected 创建未选择微信账号错误
func WeChatDecryptFailed ¶ added in v0.0.2
WeChatDecryptFailed 创建微信解密失败错误
func WeChatKeyExtractFailed ¶ added in v0.0.2
WeChatKeyExtractFailed 创建微信密钥提取失败错误
func WeChatProcessNotFound ¶ added in v0.0.2
func WeChatProcessNotFound() *AppError
WeChatProcessNotFound 创建微信进程未找到错误
func (*AppError) WithRequestID ¶ added in v0.0.2
WithRequestID 添加请求ID到错误