blob: 51c039fc6c2963956b8cf9119c182b3119da4a87 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
package router
import (
"lain/controllers"
"lain/utils/urls"
"github.com/gofiber/fiber/v2"
)
func Initialize(router *fiber.App) {
router.Static("/static", "./static")
urls.Attach(router)
}
func ErrorHandler(ctx *fiber.Ctx, err error) error {
code := fiber.StatusInternalServerError
if e, ok := err.(*fiber.Error); ok {
code = e.Code
}
switch code {
case fiber.StatusBadRequest:
return controllers.BadRequest(ctx, err)
case fiber.StatusUnauthorized:
return controllers.Unauthorized(ctx, err)
case fiber.StatusForbidden:
return controllers.Forbidden(ctx, err)
case fiber.StatusNotFound:
return controllers.NotFound(ctx, err)
case fiber.StatusInternalServerError:
return controllers.InternalServerError(ctx, err)
default:
return controllers.DefaultError(ctx, err)
}
}
|