From dc427618b0db962188b9537f8918fb1ae34a65fa Mon Sep 17 00:00:00 2001 From: Nicky Gerritsen Date: Fri, 12 Jan 2024 14:50:02 +0100 Subject: [PATCH] Be more specific with HTTP error code (422) when you pass a wrong value for a config. 400 conflicted with general errors. --- webapp/src/Controller/API/GeneralInfoController.php | 4 ++-- webapp/tests/Unit/Controller/API/ConfigControllerTest.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/webapp/src/Controller/API/GeneralInfoController.php b/webapp/src/Controller/API/GeneralInfoController.php index 0de157989d..d2555439c8 100644 --- a/webapp/src/Controller/API/GeneralInfoController.php +++ b/webapp/src/Controller/API/GeneralInfoController.php @@ -249,7 +249,7 @@ public function getDatabaseConfigurationAction( content: new OA\JsonContent(type: 'object') )] #[OA\Response( - response: 400, + response: 422, description: 'An error occurred while saving the configuration', content: new OA\JsonContent( properties: [ @@ -271,7 +271,7 @@ public function updateConfigurationAction(Request $request): JsonResponse|array { $errors = $this->config->saveChanges($request->request->all(), $this->eventLogService, $this->dj); if (!empty($errors)) { - return new JsonResponse(['errors' => $errors], 400); + return new JsonResponse(['errors' => $errors], Response::HTTP_UNPROCESSABLE_ENTITY); } return $this->config->all(false); } diff --git a/webapp/tests/Unit/Controller/API/ConfigControllerTest.php b/webapp/tests/Unit/Controller/API/ConfigControllerTest.php index 7eb77e0b6b..1f7530a251 100644 --- a/webapp/tests/Unit/Controller/API/ConfigControllerTest.php +++ b/webapp/tests/Unit/Controller/API/ConfigControllerTest.php @@ -118,7 +118,7 @@ public function testConfigChangeAPIInvalid( static::assertEquals($currentValue, $response[$property]); $proposedChange = [$property => $newValue]; - $response = $this->verifyApiJsonResponse('PUT', $this->endpoint, 400, 'admin', $proposedChange); + $response = $this->verifyApiJsonResponse('PUT', $this->endpoint, 422, 'admin', $proposedChange); static::assertEquals(['errors' => [$property => $errorMessage]], $response); }