diff options
author | Sebastian <sebasjm@gmail.com> | 2024-03-06 11:07:42 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2024-03-06 11:07:42 -0300 |
commit | e89d2098041d265131915c4e006a51478ff664bb (patch) | |
tree | 45c4433147eb989efce148a8d9c00b541872cbe3 /packages/taler-wallet-webextension/src/wallet/AddBackupProvider/state.ts | |
parent | 541886750eb1bc32b9aa0323868dd24776baf0eb (diff) | |
download | wallet-core-e89d2098041d265131915c4e006a51478ff664bb.tar.xz |
fix #8564
Diffstat (limited to 'packages/taler-wallet-webextension/src/wallet/AddBackupProvider/state.ts')
-rw-r--r-- | packages/taler-wallet-webextension/src/wallet/AddBackupProvider/state.ts | 71 |
1 files changed, 37 insertions, 34 deletions
diff --git a/packages/taler-wallet-webextension/src/wallet/AddBackupProvider/state.ts b/packages/taler-wallet-webextension/src/wallet/AddBackupProvider/state.ts index e6d46a626..75b8e53c0 100644 --- a/packages/taler-wallet-webextension/src/wallet/AddBackupProvider/state.ts +++ b/packages/taler-wallet-webextension/src/wallet/AddBackupProvider/state.ts @@ -99,42 +99,45 @@ function useUrlState<T>( } const constHref = href; - useDebounceEffect( - 500, - constHref == undefined - ? undefined - : async () => { - const req = await fetch(constHref).catch((e) => { - return setState({ - status: "network-error", - href: constHref, - }); - }); - if (!req) return; + async function checkURL() { + if (!constHref) { + return; + } + const req = await fetch(constHref).catch((e) => { + return setState({ + status: "network-error", + href: constHref, + }); + }); + if (!req) return; + + if (req.status >= 400 && req.status < 500) { + setState({ + status: "client-error", + code: req.status, + }); + return; + } + if (req.status > 500) { + setState({ + status: "server-error", + code: req.status, + }); + return; + } - if (req.status >= 400 && req.status < 500) { - setState({ - status: "client-error", - code: req.status, - }); - return; - } - if (req.status > 500) { - setState({ - status: "server-error", - code: req.status, - }); - return; - } + const json = await req.json(); + try { + const result = codec.decode(json); + setState({ status: "ok", result }); + } catch (e: any) { + setState({ status: "parsing-error", json }); + } + } - const json = await req.json(); - try { - const result = codec.decode(json); - setState({ status: "ok", result }); - } catch (e: any) { - setState({ status: "parsing-error", json }); - } - }, + useDebounceEffect( + 500, + constHref == undefined ? undefined : checkURL, [host, path], ); |