diff options
author | Nullptrderef <nullptrderef@proton.me> | 2024-04-21 09:48:22 +0200 |
---|---|---|
committer | Nullptrderef <nullptrderef@proton.me> | 2024-04-21 09:48:22 +0200 |
commit | 9b1d1feacd62d259cd56d6ed781d3ed34176db43 (patch) | |
tree | 7a02500d03bc1758678eb585f8f9ab0afa61536f /packages/anastasis-webui/src/pages/home/AddingProviderScreen | |
parent | 5cab30306ad6e69abba5979beb08276891e4b22b (diff) | |
download | wallet-core-9b1d1feacd62d259cd56d6ed781d3ed34176db43.tar.xz |
handle error
Diffstat (limited to 'packages/anastasis-webui/src/pages/home/AddingProviderScreen')
-rw-r--r-- | packages/anastasis-webui/src/pages/home/AddingProviderScreen/index.ts | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/packages/anastasis-webui/src/pages/home/AddingProviderScreen/index.ts b/packages/anastasis-webui/src/pages/home/AddingProviderScreen/index.ts index 0ab275f54..7da3ea217 100644 --- a/packages/anastasis-webui/src/pages/home/AddingProviderScreen/index.ts +++ b/packages/anastasis-webui/src/pages/home/AddingProviderScreen/index.ts @@ -24,7 +24,7 @@ import { WithoutProviderType, WithProviderType } from "./views.js"; export type AuthProvByStatusMap = Record< AuthenticationProviderStatus["status"], (AuthenticationProviderStatus & { url: string })[] -> +>; export type State = NoReducer | InvalidState | WithType | WithoutType; @@ -63,16 +63,29 @@ const map: StateViewMap<State> = { "without-type": WithoutProviderType, }; -export default compose("AddingProviderScreen", useComponentState, map) - +export default compose("AddingProviderScreen", useComponentState, map); export async function testProvider( url: string, expectedMethodType?: string, ): Promise<void> { try { - const response = await fetch(new URL("config", url).href); - const json = await response.json().catch((d) => ({})); + // TODO: look into using core.getProviderInfo :) + const json = await fetch(new URL("config", url).href) + .catch((error) => { + console.error("Provider HTTP Error:", error); + throw new Error( + "Encountered a fatal error whilst testing the provider: " + url, + ); + }) + .then((response) => + response.json().catch((error) => { + console.error("Provider Parsing Error:", error); + throw new Error( + "Encountered a fatal error whilst testing the provider: " + url, + ); + }), + ); if (!("methods" in json) || !Array.isArray(json.methods)) { throw Error( "This provider doesn't have authentication method. Check the provider URL", @@ -96,8 +109,8 @@ export async function testProvider( const error = e instanceof Error ? Error( - `There was an error testing this provider, try another one. ${e.message}`, - ) + `There was an error testing this provider, try another one. ${e.message}`, + ) : Error(`There was an error testing this provider, try another one.`); throw error; } |