forked from baron/baron-sso
i18n 광역 적용
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"baron-sso-backend/internal/idp"
|
||||
"baron-sso-backend/internal/logger"
|
||||
"baron-sso-backend/internal/middleware"
|
||||
"baron-sso-backend/internal/response"
|
||||
"baron-sso-backend/internal/repository"
|
||||
"baron-sso-backend/internal/service"
|
||||
"baron-sso-backend/internal/validator"
|
||||
@@ -292,16 +293,12 @@ func main() {
|
||||
"method", c.Method(),
|
||||
)
|
||||
// Return masked message
|
||||
return c.Status(code).JSON(fiber.Map{
|
||||
"error": "Internal Server Error",
|
||||
})
|
||||
return response.Error(c, code, response.StatusCode(code), "Internal Server Error")
|
||||
}
|
||||
}
|
||||
|
||||
// For development or non-500 errors, return the actual error message
|
||||
return c.Status(code).JSON(fiber.Map{
|
||||
"error": err.Error(),
|
||||
})
|
||||
return response.Error(c, code, response.StatusCode(code), err.Error())
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
44
backend/internal/response/error_response.go
Normal file
44
backend/internal/response/error_response.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package response
|
||||
|
||||
import "github.com/gofiber/fiber/v2"
|
||||
|
||||
type ErrorResponse struct {
|
||||
Error string `json:"error"`
|
||||
Code string `json:"code,omitempty"`
|
||||
Details interface{} `json:"details,omitempty"`
|
||||
}
|
||||
|
||||
func Error(c *fiber.Ctx, status int, code, message string) error {
|
||||
return ErrorWithDetails(c, status, code, message, nil)
|
||||
}
|
||||
|
||||
func ErrorWithDetails(c *fiber.Ctx, status int, code, message string, details interface{}) error {
|
||||
resp := ErrorResponse{
|
||||
Error: message,
|
||||
Code: code,
|
||||
Details: details,
|
||||
}
|
||||
|
||||
return c.Status(status).JSON(resp)
|
||||
}
|
||||
|
||||
func StatusCode(status int) string {
|
||||
switch status {
|
||||
case fiber.StatusBadRequest:
|
||||
return "bad_request"
|
||||
case fiber.StatusUnauthorized:
|
||||
return "invalid_session"
|
||||
case fiber.StatusForbidden:
|
||||
return "forbidden"
|
||||
case fiber.StatusNotFound:
|
||||
return "not_found"
|
||||
case fiber.StatusConflict:
|
||||
return "conflict"
|
||||
case fiber.StatusTooManyRequests:
|
||||
return "rate_limited"
|
||||
case fiber.StatusServiceUnavailable:
|
||||
return "service_unavailable"
|
||||
default:
|
||||
return "internal_error"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user