Better error handling

This commit is contained in:
Lilleman auf Larv 2021-06-24 00:46:28 +02:00
parent ee15057b13
commit 227132413a
2 changed files with 7 additions and 1 deletions

View File

@ -30,7 +30,7 @@ func (h Handlers) AccountDel(c *fiber.Ctx) error {
return c.Status(400).JSON([]ResJSONError{{Error: "Invalid uuid format"}})
}
authErr := h.RequireAdminRole(c)
authErr := h.RequireAdminRoleOrAccountID(c, accountID)
if authErr != nil {
return c.Status(403).JSON([]ResJSONError{{Error: authErr.Error()}})
}

View File

@ -2,6 +2,7 @@ package handlers
import (
"github.com/gofiber/fiber/v2"
"github.com/google/uuid"
)
// AccountGet godoc
@ -22,6 +23,11 @@ import (
func (h Handlers) AccountGet(c *fiber.Ctx) error {
accountID := c.Params("accountID")
_, uuidErr := uuid.Parse(accountID)
if uuidErr != nil {
return c.Status(400).JSON([]ResJSONError{{Error: "Invalid uuid format"}})
}
authErr := h.RequireAdminRoleOrAccountID(c, accountID)
if authErr != nil {
return c.Status(403).JSON([]ResJSONError{{Error: authErr.Error()}})