Skip to content

Commit 3eb0bb7

Browse files
committed
refactor: update api.tsx
- minor formatting and cleanup
1 parent 10fac25 commit 3eb0bb7

File tree

1 file changed

+16
-19
lines changed

1 file changed

+16
-19
lines changed

src/store/context/api.tsx

+16-19
Original file line numberDiff line numberDiff line change
@@ -374,25 +374,26 @@ export const AppAPIProvider: Component<Context> = (props) => {
374374
})
375375
const config_json = JSON.parse(config)
376376
trace(`[Config]: ${JSON.stringify(config_json)}`)
377-
if (response instanceof Object && response.ok) {
378-
if (config !== '') {
379-
if (response.data['name'] !== config_json.version) {
380-
// update config
381-
setGHData(response.data, true)
382-
debug(
383-
'[Config Exists]: Config Exists and is out of date - Updating',
384-
)
385-
setGHRestStatus(RESTStatus.COMPLETE)
386-
return
387-
}
388-
}
377+
if (
378+
(!response.ok || !(response instanceof Object)) &&
379+
config === ''
380+
) {
381+
warn('[Config Exists]: Most likely rate limited')
382+
setGHData(config_json, false)
383+
setGHRestStatus(RESTStatus.COMPLETE)
384+
return
385+
}
386+
if (response.data['name'] === config_json.version) {
389387
debug('[Config Exists]: Config Exists and is up to date')
390388
setGHData(response.data, false)
391389
return
392390
}
393-
warn('[Config Exists]: Most likely rate limited')
394-
setGHData(config_json, false)
391+
392+
// update config
393+
setGHData(response.data, true)
394+
debug('[Config Exists]: Config Exists and is out of date - Updating')
395395
setGHRestStatus(RESTStatus.COMPLETE)
396+
return
396397
} catch (err) {
397398
setGHRestStatus(RESTStatus.NO_CONFIG)
398399
if (response.ok) {
@@ -447,7 +448,7 @@ export const AppAPIProvider: Component<Context> = (props) => {
447448
}
448449
}
449450

450-
const RequestHook = async (
451+
const useRequestHook = async (
451452
endpointName: string,
452453
deviceName?: string,
453454
args?: string,
@@ -487,10 +488,6 @@ export const AppAPIProvider: Component<Context> = (props) => {
487488
}
488489
}
489490

490-
const useRequestHook = async (endpointName: string, deviceName?: string, args?: string) => {
491-
await RequestHook(endpointName, deviceName, args)
492-
}
493-
494491
/**
495492
* @description Uploads a firmware to a device
496493
* @param firmwareName The name of the firmware file

0 commit comments

Comments
 (0)