Skip to content

Commit

Permalink
✨ new wrapper render.ErrorNotFound()
Browse files Browse the repository at this point in the history
  • Loading branch information
acidjazz committed Sep 14, 2023
1 parent 1425912 commit 8cd6a0c
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions render/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,21 @@ func Error(c *fiber.Ctx, errors any) error {
return c.Status(http.StatusBadRequest).JSON(H{"error": true, "errors": errors})
}

func ErrorPayment(c *fiber.Ctx, message string) error {
return c.Status(http.StatusPaymentRequired).JSON(H{"error": true, "errors": [1]string{message}})
}

func ErrorCustom(c *fiber.Ctx, status int, errors any) error {
if reflect.TypeOf(errors).Kind() == reflect.String {
errors = [1]string{fmt.Sprintf("%v", errors)}
}
return c.Status(status).JSON(H{"error": true, "errors": errors})
}

func ErrorNotFound(c *fiber.Ctx, errors any) error {
return ErrorCustom(c, http.StatusNotFound, errors)
}

func ErrorPayment(c *fiber.Ctx, errors any) error {
return ErrorCustom(c, http.StatusPaymentRequired, errors)
}

func Unauthorized(c *fiber.Ctx) error {
return c.Status(http.StatusUnauthorized).JSON(H{"error": true, "errors": [1]string{"Unauthorized"}})
}
Expand Down

0 comments on commit 8cd6a0c

Please sign in to comment.