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 1/3] 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) { From 74f09acc683483dcc1df85065164a9bd5771bf45 Mon Sep 17 00:00:00 2001 From: Calum McGowan <142215111+calummcgowan@users.noreply.github.com> Date: Fri, 8 Nov 2024 09:19:10 +0000 Subject: [PATCH 2/3] lint-format async-await fix --- frontend/src/service/defenceService.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/service/defenceService.ts b/frontend/src/service/defenceService.ts index 0cb1cfe0..315ce3a3 100644 --- a/frontend/src/service/defenceService.ts +++ b/frontend/src/service/defenceService.ts @@ -85,7 +85,7 @@ async function resetDefenceConfigItem( return (await response.json()) as DefenceResetResponse; }, async () => { - return null; + return await null; } ); } From 98d82b0539df16b5b04327daf5545318773e5f46 Mon Sep 17 00:00:00 2001 From: Calum McGowan <142215111+calummcgowan@users.noreply.github.com> Date: Fri, 8 Nov 2024 09:26:26 +0000 Subject: [PATCH 3/3] lint-format fix v2 --- frontend/src/service/defenceService.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frontend/src/service/defenceService.ts b/frontend/src/service/defenceService.ts index 315ce3a3..933fad18 100644 --- a/frontend/src/service/defenceService.ts +++ b/frontend/src/service/defenceService.ts @@ -84,8 +84,8 @@ async function resetDefenceConfigItem( async (response) => { return (await response.json()) as DefenceResetResponse; }, - async () => { - return await null; + () => { + return null; } ); }