[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-wallet-core] branch master updated: show reducer network errors
From: |
gnunet |
Subject: |
[taler-wallet-core] branch master updated: show reducer network errors |
Date: |
Thu, 14 Oct 2021 17:08:46 +0200 |
This is an automated email from the git hooks/post-receive script.
dold pushed a commit to branch master
in repository wallet-core.
The following commit(s) were added to refs/heads/master by this push:
new 90f4a4e6 show reducer network errors
90f4a4e6 is described below
commit 90f4a4e655347fbb4ce83c765f3b1c8c48d5cd22
Author: Florian Dold <florian@dold.me>
AuthorDate: Thu Oct 14 17:08:41 2021 +0200
show reducer network errors
---
.../src/hooks/use-anastasis-reducer.ts | 115 ++++++++++++++++-----
1 file changed, 88 insertions(+), 27 deletions(-)
diff --git a/packages/anastasis-webui/src/hooks/use-anastasis-reducer.ts
b/packages/anastasis-webui/src/hooks/use-anastasis-reducer.ts
index 3acaaa36..110ec016 100644
--- a/packages/anastasis-webui/src/hooks/use-anastasis-reducer.ts
+++ b/packages/anastasis-webui/src/hooks/use-anastasis-reducer.ts
@@ -1,3 +1,4 @@
+import { TalerErrorCode } from "@gnu-taler/taler-util";
import { useState } from "preact/hooks";
export type ReducerState =
@@ -138,13 +139,44 @@ export enum RecoveryStates {
const reducerBaseUrl = "http://localhost:5000/";
async function getBackupStartState(): Promise<ReducerState> {
- const resp = await fetch(new URL("start-backup", reducerBaseUrl).href);
- return await resp.json();
+ let resp: Response;
+
+ try {
+ resp = await fetch(new URL("start-backup", reducerBaseUrl).href);
+ } catch (e) {
+ return {
+ code: TalerErrorCode.ANASTASIS_REDUCER_NETWORK_FAILED,
+ message: `Network request to remote reducer ${reducerBaseUrl} failed`,
+ } as any;
+ }
+ try {
+ return await resp.json();
+ } catch (e) {
+ return {
+ code: TalerErrorCode.ANASTASIS_REDUCER_NETWORK_FAILED,
+ message: `Could not parse response from reducer`,
+ } as any;
+ }
}
async function getRecoveryStartState(): Promise<ReducerState> {
- const resp = await fetch(new URL("start-recovery", reducerBaseUrl).href);
- return await resp.json();
+ let resp: Response;
+ try {
+ resp = await fetch(new URL("start-recovery", reducerBaseUrl).href);
+ } catch (e) {
+ return {
+ code: TalerErrorCode.ANASTASIS_REDUCER_NETWORK_FAILED,
+ message: `Network request to remote reducer ${reducerBaseUrl} failed`,
+ } as any;
+ }
+ try {
+ return await resp.json();
+ } catch (e) {
+ return {
+ code: TalerErrorCode.ANASTASIS_REDUCER_NETWORK_FAILED,
+ message: `Could not parse response from reducer`,
+ } as any;
+ }
}
async function reduceState(
@@ -152,19 +184,34 @@ async function reduceState(
action: string,
args: any,
): Promise<ReducerState> {
- const resp = await fetch(new URL("action", reducerBaseUrl).href, {
- method: "POST",
- headers: {
- Accept: "application/json",
- "Content-Type": "application/json",
- },
- body: JSON.stringify({
- state,
- action,
- arguments: args,
- }),
- });
- return resp.json();
+ let resp: Response;
+ try {
+ resp = await fetch(new URL("action", reducerBaseUrl).href, {
+ method: "POST",
+ headers: {
+ Accept: "application/json",
+ "Content-Type": "application/json",
+ },
+ body: JSON.stringify({
+ state,
+ action,
+ arguments: args,
+ }),
+ });
+ } catch (e) {
+ return {
+ code: TalerErrorCode.ANASTASIS_REDUCER_NETWORK_FAILED,
+ message: `Network request to remote reducer ${reducerBaseUrl} failed`,
+ } as any;
+ }
+ try {
+ return await resp.json();
+ } catch (e) {
+ return {
+ code: TalerErrorCode.ANASTASIS_REDUCER_NETWORK_FAILED,
+ message: `Could not parse response from reducer`,
+ } as any;
+ }
}
export interface ReducerTransactionHandle {
@@ -244,19 +291,33 @@ export function useAnastasisReducer():
AnastasisReducerApi {
currentError: anastasisState.currentError,
async startBackup() {
const s = await getBackupStartState();
- setAnastasisState({
- ...anastasisState,
- currentError: undefined,
- reducerState: s,
- });
+ if (s.code !== undefined) {
+ setAnastasisState({
+ ...anastasisState,
+ currentError: s,
+ });
+ } else {
+ setAnastasisState({
+ ...anastasisState,
+ currentError: undefined,
+ reducerState: s,
+ });
+ }
},
async startRecover() {
const s = await getRecoveryStartState();
- setAnastasisState({
- ...anastasisState,
- currentError: undefined,
- reducerState: s,
- });
+ if (s.code !== undefined) {
+ setAnastasisState({
+ ...anastasisState,
+ currentError: s,
+ });
+ } else {
+ setAnastasisState({
+ ...anastasisState,
+ currentError: undefined,
+ reducerState: s,
+ });
+ }
},
transition(action: string, args: any) {
doTransition(action, args);
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [taler-wallet-core] branch master updated: show reducer network errors,
gnunet <=