summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNullptrderef <nullptrderef@proton.me>2024-04-21 09:51:15 +0200
committerNullptrderef <nullptrderef@proton.me>2024-04-21 09:51:15 +0200
commit8841c30a571f751fc4f9a5a7e7cb9b220618b0c5 (patch)
treebe3c17d788992da61ba9a18dc8ad53fe2163baec
parent9b1d1feacd62d259cd56d6ed781d3ed34176db43 (diff)
downloadwallet-core-8841c30a571f751fc4f9a5a7e7cb9b220618b0c5.tar.gz
wallet-core-8841c30a571f751fc4f9a5a7e7cb9b220618b0c5.tar.bz2
wallet-core-8841c30a571f751fc4f9a5a7e7cb9b220618b0c5.zip
use new Error (standard, as error is a class)
-rw-r--r--packages/anastasis-webui/src/hooks/use-anastasis-reducer.ts6
-rw-r--r--packages/anastasis-webui/src/index.ts2
-rw-r--r--packages/anastasis-webui/src/pages/home/AddingProviderScreen/index.ts23
3 files changed, 22 insertions, 9 deletions
diff --git a/packages/anastasis-webui/src/hooks/use-anastasis-reducer.ts b/packages/anastasis-webui/src/hooks/use-anastasis-reducer.ts
index fc8c4cf6c..fcc380775 100644
--- a/packages/anastasis-webui/src/hooks/use-anastasis-reducer.ts
+++ b/packages/anastasis-webui/src/hooks/use-anastasis-reducer.ts
@@ -303,7 +303,7 @@ export function useAnastasisReducer(): AnastasisReducerApi {
},
});
} catch (e) {
- throw Error("could not restore the state");
+ throw new Error("could not restore the state");
}
},
async discoverStart(): Promise<void> {
@@ -399,7 +399,7 @@ export function useAnastasisReducer(): AnastasisReducerApi {
}
class ReducerTxImpl implements ReducerTransactionHandle {
- constructor(public transactionState: ReducerState) { }
+ constructor(public transactionState: ReducerState) {}
async transition(action: string, args: any): Promise<ReducerState> {
let s: ReducerState;
if (remoteReducer) {
@@ -410,7 +410,7 @@ class ReducerTxImpl implements ReducerTransactionHandle {
this.transactionState = s;
// Abort transaction as soon as we transition into an error state.
if (this.transactionState.reducer_type === "error") {
- throw Error("transition resulted in error");
+ throw new Error("transition resulted in error");
}
return this.transactionState;
}
diff --git a/packages/anastasis-webui/src/index.ts b/packages/anastasis-webui/src/index.ts
index d7b2164ab..f614e4f54 100644
--- a/packages/anastasis-webui/src/index.ts
+++ b/packages/anastasis-webui/src/index.ts
@@ -22,7 +22,7 @@ function main(): void {
try {
const container = document.getElementById("container");
if (!container) {
- throw Error("container not found, can't mount page contents");
+ throw new Error("container not found, can't mount page contents");
}
render(h(App, {}), container);
} catch (e) {
diff --git a/packages/anastasis-webui/src/pages/home/AddingProviderScreen/index.ts b/packages/anastasis-webui/src/pages/home/AddingProviderScreen/index.ts
index 7da3ea217..5f49f39e8 100644
--- a/packages/anastasis-webui/src/pages/home/AddingProviderScreen/index.ts
+++ b/packages/anastasis-webui/src/pages/home/AddingProviderScreen/index.ts
@@ -86,9 +86,20 @@ export async function testProvider(
);
}),
);
+ if (typeof json !== "object")
+ throw new Error(
+ "Encountered a fatal error whilst testing the provider: " +
+ url +
+ "\nError: Did not get an object after decoding.",
+ );
+ if (!("name" in json) || json.name !== "anastasis") {
+ throw new Error(
+ "The provider does not appear to be an Anastasis provider. Please check the provider's URL.",
+ );
+ }
if (!("methods" in json) || !Array.isArray(json.methods)) {
- throw Error(
- "This provider doesn't have authentication method. Check the provider URL",
+ throw new Error(
+ "This provider doesn't have authentication method. Please check the provider's URL and ensure it is properly configured.",
);
}
if (!expectedMethodType) {
@@ -99,7 +110,7 @@ export async function testProvider(
found = json.methods[i].type === expectedMethodType;
}
if (!found) {
- throw Error(
+ throw new Error(
`This provider does not support authentication method ${expectedMethodType}`,
);
}
@@ -108,10 +119,12 @@ export async function testProvider(
console.log("ERROR testProvider", e);
const error =
e instanceof Error
- ? Error(
+ ? new Error(
`There was an error testing this provider, try another one. ${e.message}`,
)
- : Error(`There was an error testing this provider, try another one.`);
+ : new Error(
+ `There was an error testing this provider, try another one.`,
+ );
throw error;
}
}