From 6460ef639db8285d2fb2a4f4af5656cab846f63f Mon Sep 17 00:00:00 2001 From: DaOfficialWizard <45744329+ZanzyTHEbar@users.noreply.github.com> Date: Thu, 5 Oct 2023 17:03:29 +0100 Subject: [PATCH] fix: http client request hook --- GUI/ETVR/src/store/context/api/index.tsx | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/GUI/ETVR/src/store/context/api/index.tsx b/GUI/ETVR/src/store/context/api/index.tsx index ed8dc07..9721552 100644 --- a/GUI/ETVR/src/store/context/api/index.tsx +++ b/GUI/ETVR/src/store/context/api/index.tsx @@ -498,18 +498,19 @@ export const AppAPIProvider: Component = (props) => { setRESTStatus(RESTStatus.LOADING) try { + setRESTStatus(RESTStatus.ACTIVE) let parsedResponse: object = {} const response = await makeRequest(endpoint, deviceName, method) - if (response.status === 'ok') { - setRESTStatus(RESTStatus.ACTIVE) - - const unlisten = await listen('request-response', (event) => { - parsedResponse = JSON.parse(event.payload) - }) - - unlisten() - setRESTResponse(parsedResponse) + const unlisten = await listen('request-response', (event) => { + parsedResponse = JSON.parse(event.payload) + }) + if (response.status === 'error') { + setRESTStatus(RESTStatus.FAILED) + error(`[REST Request]: ${response.error}`) + return O.none } + unlisten() + setRESTResponse(parsedResponse) setRESTStatus(RESTStatus.COMPLETE) return O.some(parsedResponse) } catch (err) {