重构错误处理逻辑,使用 fiber.Error 统一返回错误状态码;统一授权枚举值定义到 auth 包

This commit is contained in:
2025-05-10 13:38:47 +08:00
parent a06655ad29
commit 3140d35a95
9 changed files with 103 additions and 94 deletions

View File

@@ -1,19 +1,17 @@
package core
type UnAuthorizedErr string
import "github.com/gofiber/fiber/v2"
func (e UnAuthorizedErr) Error() string {
return string(e)
// ErrInvalid 返回 400 状态码的错误
func ErrInvalid(message ...string) error {
return fiber.NewError(fiber.StatusBadRequest, message...)
}
type ForbiddenErr string
func (e ForbiddenErr) Error() string {
return string(e)
func ErrUnauthorized(message ...string) error {
return fiber.NewError(fiber.StatusUnauthorized, message...)
}
type DataErr string
func (e DataErr) Error() string {
return string(e)
// ErrForbidden 返回 403 状态码的错误
func ErrForbidden(message ...string) error {
return fiber.NewError(fiber.StatusForbidden, message...)
}