From e8f76f39e1a10fb87a2a58e9cd2464974836710b Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Thu, 30 Jun 2022 14:50:25 -0400 Subject: [PATCH 1/5] UI: Use new `/api/clear-simulation-data` endpoint --- .../src/components/ui-components/IslandResetModal.tsx | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/monkey/monkey_island/cc/ui/src/components/ui-components/IslandResetModal.tsx b/monkey/monkey_island/cc/ui/src/components/ui-components/IslandResetModal.tsx index 15281362f..7b3887f09 100644 --- a/monkey/monkey_island/cc/ui/src/components/ui-components/IslandResetModal.tsx +++ b/monkey/monkey_island/cc/ui/src/components/ui-components/IslandResetModal.tsx @@ -54,8 +54,7 @@ const IslandResetModal = (props: Props) => { @@ -97,24 +106,17 @@ const IslandResetModal = (props: Props) => { } }) } - function resetAll(callback: () => void) { - auth.authFetch('/api/reset-agent-configuration', {method: 'POST'}) + function resetAll() { + return auth.authFetch('/api/reset-agent-configuration', {method: 'POST'}) .then(res => { if (res.status === 200) { - auth.authFetch('/api/clear-simulation-data', {method: 'POST'}) - .then(res => { - if (res.status === 200) { - auth.authFetch('/api/island-mode', {method: 'POST', body: '{"mode": "unset"}'}) - .then(res => { - if (res.status === 200) { - callback(); - } - }) - } - }) - } - }) - } + return auth.authFetch('/api/clear-simulation-data', {method: 'POST'}) + }) + .then(res => { + if (res.status === 200) { + return auth.authFetch('/api/island-mode', {method: 'POST', body: '{"mode": "unset"}'}) + }) +} function showModalButtons() { return ( From a53fda39cee303b33b6c42080e830051964fe904 Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Fri, 1 Jul 2022 09:09:40 -0400 Subject: [PATCH 5/5] UI: Throw exception from resetAll() --- .../ui-components/IslandResetModal.tsx | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/monkey/monkey_island/cc/ui/src/components/ui-components/IslandResetModal.tsx b/monkey/monkey_island/cc/ui/src/components/ui-components/IslandResetModal.tsx index a6eef2070..8936cc077 100644 --- a/monkey/monkey_island/cc/ui/src/components/ui-components/IslandResetModal.tsx +++ b/monkey/monkey_island/cc/ui/src/components/ui-components/IslandResetModal.tsx @@ -75,16 +75,11 @@ const IslandResetModal = (props: Props) => { onClick={() => { setResetAll(Loading); try { - resetAll().then(res => { - if (res.status === 200) { - setResetAll(Done); - props.onClose(); - } else { - throw 'Error resetting the simulation' - } - }) + resetAll(); + setResetAll(Done); + props.onClose(); } catch (err) { - // TODO: Display error message + // TODO: Display error message to user console.error(err) } }}> @@ -107,7 +102,7 @@ const IslandResetModal = (props: Props) => { }) } function resetAll() { - return auth.authFetch('/api/reset-agent-configuration', {method: 'POST'}) + auth.authFetch('/api/reset-agent-configuration', {method: 'POST'}) .then(res => { if (res.status === 200) { return auth.authFetch('/api/clear-simulation-data', {method: 'POST'}) @@ -116,6 +111,11 @@ const IslandResetModal = (props: Props) => { if (res.status === 200) { return auth.authFetch('/api/island-mode', {method: 'POST', body: '{"mode": "unset"}'}) }) + .then(res => { + if (res.status !== 200) { + throw 'Error resetting the simulation' + } + }) } function showModalButtons() {