commit 9b1d1feacd62d259cd56d6ed781d3ed34176db43
parent 5cab30306ad6e69abba5979beb08276891e4b22b
Author: Nullptrderef <nullptrderef@proton.me>
Date: Sun, 21 Apr 2024 09:48:22 +0200
handle error
Diffstat:
1 file 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
@@ -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;
}