aboutsummaryrefslogtreecommitdiff
path: root/packages/web-util/src/context/merchant-api.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/web-util/src/context/merchant-api.ts')
-rw-r--r--packages/web-util/src/context/merchant-api.ts26
1 files changed, 21 insertions, 5 deletions
diff --git a/packages/web-util/src/context/merchant-api.ts b/packages/web-util/src/context/merchant-api.ts
index 604119e84..9998b3aeb 100644
--- a/packages/web-util/src/context/merchant-api.ts
+++ b/packages/web-util/src/context/merchant-api.ts
@@ -81,6 +81,8 @@ export type ConfigResultFail<T> =
| { type: "incompatible"; result: T; supported: string }
| { type: "error"; error: TalerError };
+const CONFIG_FAIL_TRY_AGAIN_MS = 5000
+
export const MerchantApiProvider = ({
baseUrl,
children,
@@ -103,8 +105,10 @@ export const MerchantApiProvider = ({
buildMerchantApiClient(merchantEndpoint, evictors);
useEffect(() => {
- getRemoteConfig()
- .then((config) => {
+ let keepRetrying = true;
+ async function testConfig(): Promise<void> {
+ try {
+ const config = await getRemoteConfig();
if (LibtoolVersion.compare(VERSION, config.version)) {
setChecked({ type: "ok", config, hints: [] });
} else {
@@ -114,12 +118,24 @@ export const MerchantApiProvider = ({
supported: VERSION,
});
}
- })
- .catch((error: unknown) => {
+ } catch (error) {
if (error instanceof TalerError) {
+ if (keepRetrying) {
+ setTimeout(() => {
+ testConfig()
+ }, CONFIG_FAIL_TRY_AGAIN_MS);
+ }
setChecked({ type: "error", error });
+ } else {
+ setChecked({ type: "error", error: TalerError.fromException(error) });
}
- });
+ }
+ }
+ testConfig();
+ return () => {
+ // on unload, stop retry
+ keepRetrying = false;
+ }
}, []);
if (!checked || checked.type !== "ok") {