From 3b5ecd08ff8fc7bc7fa502cef5a0dd652447967a Mon Sep 17 00:00:00 2001 From: Daniel Kesselberg Date: Mon, 30 Oct 2023 12:52:35 +0100 Subject: [PATCH] fix: dont forward internal exceptions Signed-off-by: Daniel Kesselberg --- lib/Controller/AppointmentConfigController.php | 8 ++++---- src/services/appointmentConfigService.js | 4 +++- .../unit/Controller/AppointmentConfigControllerTest.php | 4 ++-- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/Controller/AppointmentConfigController.php b/lib/Controller/AppointmentConfigController.php index 9a566d27b6..84260799a5 100644 --- a/lib/Controller/AppointmentConfigController.php +++ b/lib/Controller/AppointmentConfigController.php @@ -199,7 +199,7 @@ public function create( return JsonResponse::success($appointmentConfig); } catch (ServiceException $e) { $this->logger->error('Could not create new configuration', ['exception' => $e]); - return JsonResponse::errorFromThrowable($e); + return JsonResponse::fail($e->getMessage(), Http::STATUS_INTERNAL_SERVER_ERROR); } } @@ -257,7 +257,7 @@ public function update( $appointmentConfig = $this->appointmentConfigService->findByIdAndUser($id, $this->userId); } catch (ClientException $e) { $this->logger->error('Could not find configuration with id ' . $id, ['exception' => $e]); - return JsonResponse::errorFromThrowable($e); + return JsonResponse::fail($e->getMessage(), Http::STATUS_NOT_FOUND); } $appointmentConfig->setName($name); @@ -284,7 +284,7 @@ public function update( return JsonResponse::success($appointmentConfig); } catch (ServiceException $e) { $this->logger->error('Could not update configuration with id ' . $id, ['exception' => $e]); - return JsonResponse::errorFromThrowable($e, 403); + return JsonResponse::fail($e->getMessage(), Http::STATUS_INTERNAL_SERVER_ERROR); } } @@ -303,7 +303,7 @@ public function destroy(int $id): JsonResponse { return JsonResponse::success(); } catch (ServiceException $e) { $this->logger->error('Could not delete configuration with id ' . $id, ['exception' => $e]); - return JsonResponse::errorFromThrowable($e, 403); + return JsonResponse::fail($e->getMessage(), Http::STATUS_INTERNAL_SERVER_ERROR); } } } diff --git a/src/services/appointmentConfigService.js b/src/services/appointmentConfigService.js index 546cb2afe7..4da6d836c7 100644 --- a/src/services/appointmentConfigService.js +++ b/src/services/appointmentConfigService.js @@ -32,6 +32,7 @@ import logger from '../utils/logger.js' * @return {Promise} Full appointment config with an id */ export async function createConfig(config) { + logger.debug('Creating appointment config', { config }) const url = generateUrl('/apps/calendar/v1/appointment_configs') const response = await axios.post(url, config) @@ -45,6 +46,7 @@ export async function createConfig(config) { * @return {Promise} */ export async function deleteConfig(id) { + logger.debug('Deleting appointment config', { id }) const url = generateUrl('/apps/calendar/v1/appointment_configs/{id}', { id, }) @@ -59,7 +61,7 @@ export async function deleteConfig(id) { * @return {Promise} Updated appointment config as stored in the backend */ export async function updateConfig(config) { - logger.info('Deleting config', { config, id: config.id }) + logger.debug('Updating appointment config', { config }) const url = generateUrl('/apps/calendar/v1/appointment_configs/{id}', { id: config.id, }) diff --git a/tests/php/unit/Controller/AppointmentConfigControllerTest.php b/tests/php/unit/Controller/AppointmentConfigControllerTest.php index 5e2aaced1b..19f858af57 100644 --- a/tests/php/unit/Controller/AppointmentConfigControllerTest.php +++ b/tests/php/unit/Controller/AppointmentConfigControllerTest.php @@ -288,7 +288,7 @@ public function testUpdateNotFound(): void { 5 * 60 ); - self::assertEquals(500, $response->getStatus()); + self::assertEquals(404, $response->getStatus()); } public function testUpdateDBException(): void { @@ -319,6 +319,6 @@ public function testUpdateDBException(): void { 5 * 60 ); - self::assertEquals(403, $response->getStatus()); + self::assertEquals(500, $response->getStatus()); } }