mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
28 lines
729 B
Go
28 lines
729 B
Go
package utils
|
|
|
|
import (
|
|
"errors"
|
|
|
|
"gitlab.com/mbugroup/lti-api.git/internal/common/validation"
|
|
"gitlab.com/mbugroup/lti-api.git/internal/response"
|
|
|
|
"github.com/gofiber/fiber/v2"
|
|
)
|
|
|
|
func ErrorHandler(c *fiber.Ctx, err error) error {
|
|
if message, errorsMap := validation.CustomErrorMessages(err); len(errorsMap) > 0 {
|
|
return response.Error(c, fiber.StatusBadRequest, message, nil)
|
|
}
|
|
|
|
var fiberErr *fiber.Error
|
|
if errors.As(err, &fiberErr) {
|
|
return response.Error(c, fiberErr.Code, fiberErr.Message, nil)
|
|
}
|
|
|
|
return response.Error(c, fiber.StatusInternalServerError, "Internal Server Error", nil)
|
|
}
|
|
|
|
func NotFoundHandler(c *fiber.Ctx) error {
|
|
return response.Error(c, fiber.StatusNotFound, "Endpoint Not Found", nil)
|
|
}
|