UI: Throw exception from resetAll()

This commit is contained in:
Mike Salvatore 2022-07-01 09:09:40 -04:00
parent d8a7ac3fb6
commit a53fda39ce
1 changed files with 10 additions and 10 deletions

View File

@ -75,16 +75,11 @@ const IslandResetModal = (props: Props) => {
onClick={() => { onClick={() => {
setResetAll(Loading); setResetAll(Loading);
try { try {
resetAll().then(res => { resetAll();
if (res.status === 200) { setResetAll(Done);
setResetAll(Done); props.onClose();
props.onClose();
} else {
throw 'Error resetting the simulation'
}
})
} catch (err) { } catch (err) {
// TODO: Display error message // TODO: Display error message to user
console.error(err) console.error(err)
} }
}}> }}>
@ -107,7 +102,7 @@ const IslandResetModal = (props: Props) => {
}) })
} }
function resetAll() { function resetAll() {
return auth.authFetch('/api/reset-agent-configuration', {method: 'POST'}) auth.authFetch('/api/reset-agent-configuration', {method: 'POST'})
.then(res => { .then(res => {
if (res.status === 200) { if (res.status === 200) {
return auth.authFetch('/api/clear-simulation-data', {method: 'POST'}) return auth.authFetch('/api/clear-simulation-data', {method: 'POST'})
@ -116,6 +111,11 @@ const IslandResetModal = (props: Props) => {
if (res.status === 200) { if (res.status === 200) {
return auth.authFetch('/api/island-mode', {method: 'POST', body: '{"mode": "unset"}'}) return auth.authFetch('/api/island-mode', {method: 'POST', body: '{"mode": "unset"}'})
}) })
.then(res => {
if (res.status !== 200) {
throw 'Error resetting the simulation'
}
})
} }
function showModalButtons() { function showModalButtons() {