diff --git a/backend/api/EventHandlers/MqttEventHandler.cs b/backend/api/EventHandlers/MqttEventHandler.cs index 020ed71fd..99bbd9b71 100644 --- a/backend/api/EventHandlers/MqttEventHandler.cs +++ b/backend/api/EventHandlers/MqttEventHandler.cs @@ -206,7 +206,10 @@ private async void OnMissionUpdate(object? sender, MqttReceivedArgs mqttArgs) return; } - var flotillaMissionRun = await missionRunService.UpdateMissionRunStatusByIsarMissionId(isarMission.MissionId, status); + MissionRun? flotillaMissionRun; + try { flotillaMissionRun = await missionRunService.UpdateMissionRunStatusByIsarMissionId(isarMission.MissionId, status); } + catch (MissionRunNotFoundException) { return; } + if (flotillaMissionRun is null) { _logger.LogError("No mission found with ISARMissionId '{IsarMissionId}'. Could not update status to '{Status}'", isarMission.MissionId, status); diff --git a/backend/api/Services/MissionRunService.cs b/backend/api/Services/MissionRunService.cs index 67f7c7b36..0e738ae45 100644 --- a/backend/api/Services/MissionRunService.cs +++ b/backend/api/Services/MissionRunService.cs @@ -4,10 +4,8 @@ using Api.Database.Context; using Api.Database.Models; using Api.Services.Events; -using Api.Services.Models; using Api.Utilities; using Microsoft.EntityFrameworkCore; -using TaskStatus = Api.Database.Models.TaskStatus; namespace Api.Services { public interface IMissionRunService @@ -321,19 +319,14 @@ MissionRunQueryStringParameters parameters ); } - public async Task UpdateMissionRunStatusByIsarMissionId( - string isarMissionId, - MissionStatus missionStatus - ) + public async Task UpdateMissionRunStatusByIsarMissionId(string isarMissionId, MissionStatus missionStatus) { var missionRun = await ReadByIsarMissionId(isarMissionId); if (missionRun is null) { - _logger.LogWarning( - "Could not update mission status for ISAR mission with id: {id} as the mission was not found", - isarMissionId - ); - return null; + string errorMessage = $"Mission with isar mission Id {isarMissionId} was not found"; + _logger.LogError("{Message}", errorMessage); + throw new MissionRunNotFoundException(errorMessage); } missionRun.Status = missionStatus; diff --git a/backend/api/Utilities/Exceptions.cs b/backend/api/Utilities/Exceptions.cs index 38b3c8ee0..2897d38c1 100644 --- a/backend/api/Utilities/Exceptions.cs +++ b/backend/api/Utilities/Exceptions.cs @@ -61,6 +61,11 @@ public class MissionTaskNotFoundException : Exception public MissionTaskNotFoundException(string message) : base(message) { } } + public class MissionRunNotFoundException : Exception + { + public MissionRunNotFoundException(string message) : base(message) { } + } + public class RobotPositionNotFoundException : Exception { public RobotPositionNotFoundException(string message) : base(message) { }