diff options
| author | Bobby <[email protected]> | 2025-12-19 18:52:39 +0530 |
|---|---|---|
| committer | Bobby <[email protected]> | 2025-12-19 18:52:39 +0530 |
| commit | ed74f2cffa902a3e9aeb614f8dcf65f04658a597 (patch) | |
| tree | a86fe689686774b2915608a511ba57822b0b6521 /controllers | |
| parent | a42fcbc8149f482d65a53ddcdc7bcfaaea359c69 (diff) | |
| download | lain-ed74f2cffa902a3e9aeb614f8dcf65f04658a597.tar.xz lain-ed74f2cffa902a3e9aeb614f8dcf65f04658a597.zip | |
error controllers, types and templates and layouts
Diffstat (limited to 'controllers')
| -rw-r--r-- | controllers/errors.go | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/controllers/errors.go b/controllers/errors.go new file mode 100644 index 0000000..019083a --- /dev/null +++ b/controllers/errors.go @@ -0,0 +1,53 @@ +package controllers + +import ( + "lain/types" + "lain/utils/shortcuts" + + "github.com/gofiber/fiber/v2" +) + +func BadRequest(context *fiber.Ctx, err error) error { + return shortcuts.RenderError(types.TemplateError{ + Context: context, + PageTitle: "400 – Bad Request", + ErrorMessage: shortcuts.BuildErrorMessage(err, "The request could not be understood by the server."), + StatusCode: fiber.StatusBadRequest, + }) +} + +func Forbidden(context *fiber.Ctx, err error) error { + return shortcuts.RenderError(types.TemplateError{ + Context: context, + PageTitle: "403 – Forbidden", + ErrorMessage: shortcuts.BuildErrorMessage(err, "You do not have permission to access this resource."), + StatusCode: fiber.StatusForbidden, + }) +} + +func InternalServerError(context *fiber.Ctx, err error) error { + return shortcuts.RenderError(types.TemplateError{ + Context: context, + PageTitle: "500 – Internal Server Error", + ErrorMessage: shortcuts.BuildErrorMessage(err, "An unexpected error occurred on the server."), + StatusCode: fiber.StatusInternalServerError, + }) +} + +func NotFound(context *fiber.Ctx, err error) error { + return shortcuts.RenderError(types.TemplateError{ + Context: context, + PageTitle: "404 – Not Found", + ErrorMessage: shortcuts.BuildErrorMessage(err, "The page you are looking for does not exist."), + StatusCode: fiber.StatusNotFound, + }) +} + +func Unauthorized(context *fiber.Ctx, err error) error { + return shortcuts.RenderError(types.TemplateError{ + Context: context, + PageTitle: "401 – Unauthorized", + ErrorMessage: shortcuts.BuildErrorMessage(err, "You must be logged in to access this resource."), + StatusCode: fiber.StatusUnauthorized, + }) +} |
