From e1626bd436b6ce41dceea3e40befa5e182c99cad Mon Sep 17 00:00:00 2001 From: andchiind Date: Tue, 15 Oct 2024 14:04:39 +0200 Subject: [PATCH] Catch exceptions when making calls to ISAR --- backend/api/Services/IsarService.cs | 21 +++++++++++++------ .../api/Services/MissionSchedulingService.cs | 4 ++-- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/backend/api/Services/IsarService.cs b/backend/api/Services/IsarService.cs index b5862e6f..076be91f 100644 --- a/backend/api/Services/IsarService.cs +++ b/backend/api/Services/IsarService.cs @@ -30,12 +30,21 @@ public async Task StartMission(Robot robot, MissionRun missionRun) mission_definition = new IsarMissionDefinition(missionRun, includeStartPose: missionRun.MissionRunType == MissionRunType.Localization) }; - var response = await CallApi( - HttpMethod.Post, - robot.IsarUri, - "schedule/start-mission", - missionDefinition - ); + HttpResponseMessage? response; + try + { + response = await CallApi( + HttpMethod.Post, + robot.IsarUri, + "schedule/start-mission", + missionDefinition + ); + } + catch (Exception e) + { + logger.LogError("Encountered an exception when making an API call to ISAR: {Message}", e.Message); + throw new IsarCommunicationException(e.Message); + } if (!response.IsSuccessStatusCode) { diff --git a/backend/api/Services/MissionSchedulingService.cs b/backend/api/Services/MissionSchedulingService.cs index e4773005..3566eef3 100644 --- a/backend/api/Services/MissionSchedulingService.cs +++ b/backend/api/Services/MissionSchedulingService.cs @@ -151,11 +151,11 @@ or MissionRunNotFoundException { logger.LogError( ex, - "Mission run {MissionRunId} was not started successfully due to {ErrorMessage}", + "Mission run {MissionRunId} was not started successfully. {ErrorMessage}", missionRun.Id, ex.Message ); - await missionRunService.SetMissionRunToFailed(missionRun.Id, $"Mission run '{missionRun.Id}' was not started successfully due to '{ex.Message}'"); + await missionRunService.SetMissionRunToFailed(missionRun.Id, $"Mission run '{missionRun.Id}' was not started successfully. '{ex.Message}'"); } }