blob: cdb2ad2cf6858ac8708c76be561d6c3cb3c5391f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
package shortcuts
import "github.com/gofiber/fiber/v2"
func RouteError(context *fiber.Ctx, err *fiber.Error) error {
if isAPIRequest(context) {
return context.Status(err.Code).JSON(fiber.Map{
"error": err.Message,
})
}
return RenderWithStatus(context, "errors/error", err, err.Code)
}
func ServiceError(code int, message string) *fiber.Error {
return fiber.NewError(code, message)
}
func isAPIRequest(context *fiber.Ctx) bool {
return len(context.Path()) >= 4 && context.Path()[:4] == "/api"
}
|