Documentation
¶
Index ¶
- Constants
- Variables
- func GetHTTPStatus(code int) int
- func GetMessage(code int) string
- type AppError
- func NewBadRequestError(message string, err ...error) *AppError
- func NewConflictError(message string, err ...error) *AppError
- func NewForbiddenError(message string, err ...error) *AppError
- func NewInternalError(message string, err ...error) *AppError
- func NewNotFoundError(message string, err ...error) *AppError
- func NewUnauthorizedError(message string, err ...error) *AppError
- func NewValidationError(message string, err ...error) *AppError
Constants ¶
View Source
const ( // 4xxx 客户端错误 ErrCodeBindFailed = 4001 // 参数绑定错误 ErrCodeValidationFailed = 4002 // 数据验证失败 ErrCodeNotFound = 4003 // 资源不存在 ErrCodeRouteNotFound = 4004 // 路由不存在 ErrCodeForbidden = 4005 // 权限不足 ErrCodeDuplicate = 4007 // 资源已存在 ErrCodeRateLimitExceeded = 4008 // 速率限制 // Initialization errors ErrSystemAlreadyInitialized = 4009 // 系统已初始化 ErrInvalidInitKey = 4010 // 无效的初始化密钥 ErrInitDataCreationFailed = 5005 // 初始化数据创建失败 // 5xxx 服务端错误 ErrCodeDatabase = 5001 // 数据库错误 ErrCodeBusinessLogic = 5002 // 业务逻辑错误 ErrCodeFileUpload = 5003 // 文件上传失败 ErrCodeStorageService = 5004 // 存储服务错误 ErrCodeInternal = 5000 // 内部错误 )
Variables ¶
View Source
var ErrorMessages = map[int]string{ ErrCodeBindFailed: "参数绑定错误", ErrCodeValidationFailed: "数据验证失败", ErrCodeNotFound: "资源不存在", ErrCodeRouteNotFound: "路由不存在", ErrCodeForbidden: "权限不足", ErrCodeUnauthorized: "认证失败", ErrCodeDuplicate: "资源已存在", ErrCodeRateLimitExceeded: "速率限制超出", ErrSystemAlreadyInitialized: "系统已初始化", ErrInvalidInitKey: "无效的初始化密钥", ErrInitDataCreationFailed: "初始化数据创建失败", ErrCodeDatabase: "数据库错误", ErrCodeBusinessLogic: "业务逻辑错误", ErrCodeFileUpload: "文件上传失败", ErrCodeStorageService: "存储服务错误", ErrCodeInternal: "内部错误", }
ErrorMessages maps error codes to default messages
Functions ¶
func GetHTTPStatus ¶
GetHTTPStatus maps error codes to HTTP status codes
func GetMessage ¶
GetMessage returns the default message for an error code
Types ¶
type AppError ¶
type AppError struct {
Code int `json:"code"`
Message string `json:"message"`
Err error `json:"-"`
}
AppError represents an application error with code and message
func NewBadRequestError ¶
NewBadRequestError creates a new bad request error
func NewConflictError ¶
NewConflictError creates a new conflict error
func NewForbiddenError ¶
NewForbiddenError creates a new forbidden error
func NewInternalError ¶
NewInternalError creates a new internal error
func NewNotFoundError ¶
NewNotFoundError creates a new not found error
func NewUnauthorizedError ¶
NewUnauthorizedError creates a new unauthorized error
func NewValidationError ¶
NewValidationError creates a new validation error
Click to show internal directories.
Click to hide internal directories.