diff options
| author | Bobby <[email protected]> | 2025-12-22 12:41:27 +0530 |
|---|---|---|
| committer | Bobby <[email protected]> | 2025-12-22 12:41:27 +0530 |
| commit | f17d9142781eb1a659ea53311d9225b244ad209c (patch) | |
| tree | 1b03e1f96cca8559ad1a7e37e74279136a3bf157 /router | |
| parent | ed74f2cffa902a3e9aeb614f8dcf65f04658a597 (diff) | |
| download | lain-f17d9142781eb1a659ea53311d9225b244ad209c.tar.xz lain-f17d9142781eb1a659ea53311d9225b244ad209c.zip | |
better auth and error handler setup
Diffstat (limited to 'router')
| -rw-r--r-- | router/base.go | 13 | ||||
| -rw-r--r-- | router/router.go | 23 |
2 files changed, 36 insertions, 0 deletions
diff --git a/router/base.go b/router/base.go new file mode 100644 index 0000000..a5e8e96 --- /dev/null +++ b/router/base.go @@ -0,0 +1,13 @@ +package router + +import ( + "lain/types" + "lain/utils/shortcuts" + "lain/utils/urls" +) + +func init() { + urls.SetNamespace("") + + urls.Path(types.GET, "/", shortcuts.RedirectTo("auth.login"), "home") +} diff --git a/router/router.go b/router/router.go index e5c9303..62a7576 100644 --- a/router/router.go +++ b/router/router.go @@ -1,6 +1,7 @@ package router import ( + "lain/controllers" "lain/utils/urls" "github.com/gofiber/fiber/v2" @@ -11,3 +12,25 @@ func Initialize(router *fiber.App) { 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.StatusForbidden: + return controllers.Forbidden(ctx, err) + case fiber.StatusInternalServerError: + return controllers.InternalServerError(ctx, err) + case fiber.StatusNotFound: + return controllers.NotFound(ctx, err) + case fiber.StatusUnauthorized: + return controllers.Unauthorized(ctx, err) + default: + return controllers.DefaultError(ctx, err) + } +} |
