From eacca4ef9503175b1587633e539f0299999963f8 Mon Sep 17 00:00:00 2001 From: John O'Keefe Date: Mon, 9 Feb 2026 15:49:20 -0500 Subject: [PATCH] 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 --- internal/handlers/auth.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/internal/handlers/auth.go b/internal/handlers/auth.go index 4e5d992..3680eb9 100644 --- a/internal/handlers/auth.go +++ b/internal/handlers/auth.go @@ -776,11 +776,14 @@ func (h *AuthHandler) UpdateUserMaxDevices(c echo.Context) error { 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}, MaxDevices: pgtype.Int4{Int32: req.MaxDevices, Valid: true}, }) 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()}) }