Skip to content

Commit

Permalink
fix: dont forward internal exceptions
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Kesselberg <[email protected]>
  • Loading branch information
kesselb committed Oct 30, 2023
1 parent 8f39923 commit 261c9bd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 4 additions & 4 deletions lib/Controller/AppointmentConfigController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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_UNPROCESSABLE_ENTITY);
}
}

Expand Down Expand Up @@ -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);
Expand All @@ -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_UNPROCESSABLE_ENTITY);
}
}

Expand All @@ -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_NOT_FOUND);
}
}
}
4 changes: 3 additions & 1 deletion src/services/appointmentConfigService.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import logger from '../utils/logger.js'
* @return {Promise<AppointmentConfig>} Full appointment config with an id
*/
export async function createConfig(config) {
logger.debug('Creating appointment config', { config })

Check warning on line 35 in src/services/appointmentConfigService.js

View check run for this annotation

Codecov / codecov/patch

src/services/appointmentConfigService.js#L35

Added line #L35 was not covered by tests
const url = generateUrl('/apps/calendar/v1/appointment_configs')

const response = await axios.post(url, config)
Expand All @@ -45,6 +46,7 @@ export async function createConfig(config) {
* @return {Promise<void>}
*/
export async function deleteConfig(id) {
logger.debug('Deleting appointment config', { config })

Check failure on line 49 in src/services/appointmentConfigService.js

View workflow job for this annotation

GitHub Actions / eslint

'config' is not defined

Check warning on line 49 in src/services/appointmentConfigService.js

View check run for this annotation

Codecov / codecov/patch

src/services/appointmentConfigService.js#L49

Added line #L49 was not covered by tests
const url = generateUrl('/apps/calendar/v1/appointment_configs/{id}', {
id,
})
Expand All @@ -59,7 +61,7 @@ export async function deleteConfig(id) {
* @return {Promise<AppointmentConfig>} 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 })

Check warning on line 64 in src/services/appointmentConfigService.js

View check run for this annotation

Codecov / codecov/patch

src/services/appointmentConfigService.js#L64

Added line #L64 was not covered by tests
const url = generateUrl('/apps/calendar/v1/appointment_configs/{id}', {
id: config.id,
})
Expand Down

0 comments on commit 261c9bd

Please sign in to comment.