Skip to content

Commit

Permalink
fix: http client request hook
Browse files Browse the repository at this point in the history
  • Loading branch information
ZanzyTHEbar committed Oct 5, 2023
1 parent 7a628a6 commit 6460ef6
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions GUI/ETVR/src/store/context/api/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -498,18 +498,19 @@ export const AppAPIProvider: Component<Context> = (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<string>('request-response', (event) => {
parsedResponse = JSON.parse(event.payload)
})

unlisten()
setRESTResponse(parsedResponse)
const unlisten = await listen<string>('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) {
Expand Down

0 comments on commit 6460ef6

Please sign in to comment.