summaryrefslogtreecommitdiff
path: root/nexus/utils/shortcuts/errors.go
diff options
context:
space:
mode:
Diffstat (limited to 'nexus/utils/shortcuts/errors.go')
-rw-r--r--nexus/utils/shortcuts/errors.go20
1 files changed, 20 insertions, 0 deletions
diff --git a/nexus/utils/shortcuts/errors.go b/nexus/utils/shortcuts/errors.go
new file mode 100644
index 0000000..cdb2ad2
--- /dev/null
+++ b/nexus/utils/shortcuts/errors.go
@@ -0,0 +1,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"
+}