aboutsummaryrefslogtreecommitdiff
path: root/packages/taler-wallet-webextension/src/hooks/useAsyncAsHook.ts
diff options
context:
space:
mode:
authorSebastian <sebasjm@gmail.com>2022-01-20 13:13:53 -0300
committerSebastian <sebasjm@gmail.com>2022-01-24 09:46:20 -0300
commit2a417881bb5c67cf889d54932025badf5a85a9e0 (patch)
tree6f2dc4cd5c08bbf0f8c6a04713e954145ce1f72a /packages/taler-wallet-webextension/src/hooks/useAsyncAsHook.ts
parente38be8d8ec1bdf1c854a2391ae9f4641cb69a249 (diff)
downloadwallet-core-2a417881bb5c67cf889d54932025badf5a85a9e0.tar.gz
wallet-core-2a417881bb5c67cf889d54932025badf5a85a9e0.tar.bz2
wallet-core-2a417881bb5c67cf889d54932025badf5a85a9e0.zip
fix permission api, grouping all cta into same path
Diffstat (limited to 'packages/taler-wallet-webextension/src/hooks/useAsyncAsHook.ts')
-rw-r--r--packages/taler-wallet-webextension/src/hooks/useAsyncAsHook.ts20
1 files changed, 16 insertions, 4 deletions
diff --git a/packages/taler-wallet-webextension/src/hooks/useAsyncAsHook.ts b/packages/taler-wallet-webextension/src/hooks/useAsyncAsHook.ts
index e9f03d0fa..6efa1d181 100644
--- a/packages/taler-wallet-webextension/src/hooks/useAsyncAsHook.ts
+++ b/packages/taler-wallet-webextension/src/hooks/useAsyncAsHook.ts
@@ -13,20 +13,30 @@
You should have received a copy of the GNU General Public License along with
TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
*/
-import { NotificationType } from "@gnu-taler/taler-util";
+import { NotificationType, TalerErrorDetails } from "@gnu-taler/taler-util";
import { useEffect, useState } from "preact/hooks";
import * as wxApi from "../wxApi";
+import { OperationFailedError } from "@gnu-taler/taler-wallet-core";
interface HookOk<T> {
hasError: false;
response: T;
}
-interface HookError {
+export type HookError = HookGenericError | HookOperationalError
+
+export interface HookGenericError {
hasError: true;
+ operational: false,
message: string;
}
+export interface HookOperationalError {
+ hasError: true;
+ operational: true,
+ details: TalerErrorDetails;
+}
+
export type HookResponse<T> = HookOk<T> | HookError | undefined;
//"withdraw-group-finished"
@@ -41,8 +51,10 @@ export function useAsyncAsHook<T>(
const response = await fn();
setHookResponse({ hasError: false, response });
} catch (e) {
- if (e instanceof Error) {
- setHookResponse({ hasError: true, message: e.message });
+ if (e instanceof OperationFailedError) {
+ setHookResponse({ hasError: true, operational: true, details: e.operationError });
+ } else if (e instanceof Error) {
+ setHookResponse({ hasError: true, operational: false, message: e.message });
}
}
}