From 303d96a1c46750872fc374417ab992143186f7db Mon Sep 17 00:00:00 2001 From: Calum McGowan <142215111+calummcgowan@users.noreply.github.com> Date: Mon, 4 Nov 2024 10:41:02 +0000 Subject: [PATCH] 714: Show error is we fail to reset defences --- .../src/components/MainComponent/MainComponent.tsx | 7 +++++++ frontend/src/service/defenceService.ts | 14 ++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/frontend/src/components/MainComponent/MainComponent.tsx b/frontend/src/components/MainComponent/MainComponent.tsx index 220564b4..528c23bd 100644 --- a/frontend/src/components/MainComponent/MainComponent.tsx +++ b/frontend/src/components/MainComponent/MainComponent.tsx @@ -226,6 +226,13 @@ function MainComponent({ configItemId, currentLevel ); + if (!resetDefence) { + addChatMessage({ + message: 'Failed to reset defence configuration. Please try again.', + type: 'ERROR_MSG', + }); + return; + } addConfigUpdateToChat(defenceId, 'reset'); // update state const newDefences = defences.map((defence) => { diff --git a/frontend/src/service/defenceService.ts b/frontend/src/service/defenceService.ts index cfe45390..0cb1cfe0 100644 --- a/frontend/src/service/defenceService.ts +++ b/frontend/src/service/defenceService.ts @@ -75,13 +75,19 @@ async function resetDefenceConfigItem( defenceId: DEFENCE_ID, configItemId: DEFENCE_CONFIG_ITEM_ID, level: LEVEL_NAMES -): Promise { - const response = await post(`${PATH}/resetConfig`, { +): Promise { + return post(`${PATH}/resetConfig`, { defenceId, configItemId, level, - }); - return (await response.json()) as DefenceResetResponse; + }).then( + async (response) => { + return (await response.json()) as DefenceResetResponse; + }, + async () => { + return null; + } + ); } function validatePositiveNumberConfig(value: string) {