Return 404 when updating max_devices for non-existent user
- Check if returned user record is null (user not found) - Return 404 Not Found instead of 200 OK - Provides accurate REST API semantics - Fixes TestUpdateUserMaxDevicesNonExistentUser Related: Database query change commit
This commit is contained in:
@@ -776,11 +776,14 @@ func (h *AuthHandler) UpdateUserMaxDevices(c echo.Context) error {
|
|||||||
return c.JSON(http.StatusBadRequest, map[string]string{"error": "invalid user id"})
|
return c.JSON(http.StatusBadRequest, map[string]string{"error": "invalid user id"})
|
||||||
}
|
}
|
||||||
|
|
||||||
err = h.db.UpdateUserMaxDevices(c.Request().Context(), database.UpdateUserMaxDevicesParams{
|
user, err := h.db.UpdateUserMaxDevices(c.Request().Context(), database.UpdateUserMaxDevicesParams{
|
||||||
ID: pgtype.UUID{Bytes: userUUID, Valid: true},
|
ID: pgtype.UUID{Bytes: userUUID, Valid: true},
|
||||||
MaxDevices: pgtype.Int4{Int32: req.MaxDevices, Valid: true},
|
MaxDevices: pgtype.Int4{Int32: req.MaxDevices, Valid: true},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if err == pgx.ErrNoRows {
|
||||||
|
return c.JSON(http.StatusNotFound, map[string]string{"error": "user not found"})
|
||||||
|
}
|
||||||
return c.JSON(http.StatusInternalServerError, map[string]string{"error": err.Error()})
|
return c.JSON(http.StatusInternalServerError, map[string]string{"error": err.Error()})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user