feat: roles, permissions
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
|
||||
var (
|
||||
// Typed errors for request validation and authentication
|
||||
ErrForbidden = errors.New("forbidden")
|
||||
ErrInvalidBody = errors.New("invalid request body")
|
||||
ErrNotAuthenticated = errors.New("not authenticated")
|
||||
ErrUserNotFound = errors.New("user not found")
|
||||
@@ -83,6 +84,8 @@ func NewError(err error, status int) *Error {
|
||||
// GetErrorCode returns the error code string for HTTP response mapping
|
||||
func GetErrorCode(c fiber.Ctx, err error) string {
|
||||
switch {
|
||||
case errors.Is(err, ErrForbidden):
|
||||
return i18n.T_(c, "error.err_forbidden")
|
||||
case errors.Is(err, ErrInvalidBody):
|
||||
return i18n.T_(c, "error.err_invalid_body")
|
||||
case errors.Is(err, ErrInvalidCredentials):
|
||||
@@ -167,6 +170,8 @@ func GetErrorCode(c fiber.Ctx, err error) string {
|
||||
// GetErrorStatus returns the HTTP status code for the given error
|
||||
func GetErrorStatus(err error) int {
|
||||
switch {
|
||||
case errors.Is(err, ErrForbidden):
|
||||
return fiber.StatusForbidden
|
||||
case errors.Is(err, ErrInvalidCredentials),
|
||||
errors.Is(err, ErrNotAuthenticated),
|
||||
errors.Is(err, ErrInvalidToken),
|
||||
|
||||
Reference in New Issue
Block a user