summaryrefslogtreecommitdiff
path: root/router/router.go
blob: 2428a8484e0c99e77be645dc3eca2c71c85baa86 (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 (
	"cafe/controllers"
	"cafe/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)
	}
}