Skip to content

Commit

Permalink
Merge pull request nextcloud#5553 from nextcloud/bug/noid/appointment…
Browse files Browse the repository at this point in the history
…-config-error-handling
  • Loading branch information
kesselb authored Oct 30, 2023
2 parents 8f39923 + 3b5ecd0 commit 4382955
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 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_INTERNAL_SERVER_ERROR);
}
}

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_INTERNAL_SERVER_ERROR);
}
}

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_INTERNAL_SERVER_ERROR);
}
}
}
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 })
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', { id })
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 })
const url = generateUrl('/apps/calendar/v1/appointment_configs/{id}', {
id: config.id,
})
Expand Down
4 changes: 2 additions & 2 deletions tests/php/unit/Controller/AppointmentConfigControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ public function testUpdateNotFound(): void {
5 * 60
);

self::assertEquals(500, $response->getStatus());
self::assertEquals(404, $response->getStatus());
}

public function testUpdateDBException(): void {
Expand Down Expand Up @@ -319,6 +319,6 @@ public function testUpdateDBException(): void {
5 * 60
);

self::assertEquals(403, $response->getStatus());
self::assertEquals(500, $response->getStatus());
}
}

0 comments on commit 4382955

Please sign in to comment.