From 55ee0901ec8dda15d46c20e78c55691ff632a9fd Mon Sep 17 00:00:00 2001 From: Alex Stelea Date: Fri, 26 Jul 2024 11:59:27 +0100 Subject: [PATCH 1/4] fix: extend sdk error --- .../simple-dapp/public/.well-known/radix.json | 1 - packages/dapp-toolkit/src/error.ts | 2 ++ .../src/modules/gateway/gateway.module.ts | 23 +++++++++++++++++-- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/examples/simple-dapp/public/.well-known/radix.json b/examples/simple-dapp/public/.well-known/radix.json index 2a1b0c64..f1984d78 100644 --- a/examples/simple-dapp/public/.well-known/radix.json +++ b/examples/simple-dapp/public/.well-known/radix.json @@ -1,5 +1,4 @@ { - "callbackPath": "/connect", "dApps": [ { "dAppDefinitionAddress": "account_tdx_2_12yf9gd53yfep7a669fv2t3wm7nz9zeezwd04n02a433ker8vza6rhe" diff --git a/packages/dapp-toolkit/src/error.ts b/packages/dapp-toolkit/src/error.ts index 13c2a86d..08d5d34f 100644 --- a/packages/dapp-toolkit/src/error.ts +++ b/packages/dapp-toolkit/src/error.ts @@ -37,8 +37,10 @@ export const SdkError = ( error: string, interactionId: string, message?: string, + jsError?: unknown, ) => ({ error, interactionId, message: message || defaultErrorMessage.get(error) || '', + jsError, }) diff --git a/packages/dapp-toolkit/src/modules/gateway/gateway.module.ts b/packages/dapp-toolkit/src/modules/gateway/gateway.module.ts index dc084882..33e45664 100644 --- a/packages/dapp-toolkit/src/modules/gateway/gateway.module.ts +++ b/packages/dapp-toolkit/src/modules/gateway/gateway.module.ts @@ -41,7 +41,16 @@ export const GatewayModule = (input: { retry.withBackoff$.pipe( switchMap((result) => { if (result.isErr()) - return [err(SdkError('failedToPollSubmittedTransaction', ''))] + return [ + err( + SdkError('failedToPollSubmittedTransaction', '', undefined, { + error: result.error, + context: + 'GatewayModule.pollTransactionStatus.retry.withBackoff$', + transactionIntentHash, + }), + ), + ] logger?.debug(`pollingTxStatus retry #${result.value + 1}`) @@ -56,7 +65,17 @@ export const GatewayModule = (input: { }) .mapErr((response) => { logger?.debug(response) - return SdkError('failedToPollSubmittedTransaction', '') + return SdkError( + 'failedToPollSubmittedTransaction', + '', + undefined, + { + error: response, + transactionIntentHash, + context: + 'GatewayModule.pollTransactionStatus.getTransactionStatus', + }, + ) }) }), filter( From 4274f08ca7bdd08506945e11aeb2ec4198b35168 Mon Sep 17 00:00:00 2001 From: Alex Stelea Date: Fri, 26 Jul 2024 12:10:46 +0100 Subject: [PATCH 2/4] fix: update sdk error type --- packages/dapp-toolkit/src/error.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/dapp-toolkit/src/error.ts b/packages/dapp-toolkit/src/error.ts index 08d5d34f..df0bd9fb 100644 --- a/packages/dapp-toolkit/src/error.ts +++ b/packages/dapp-toolkit/src/error.ts @@ -31,14 +31,19 @@ const defaultErrorMessage = new Map() .set(ErrorType.rejectedByUser, 'user rejected request') .set(ErrorType.canceledByUser, 'user has canceled the request') -export type SdkError = ReturnType +export type SdkError = { + error: string + interactionId: string + message?: string + jsError?: unknown +} export const SdkError = ( error: string, interactionId: string, message?: string, jsError?: unknown, -) => ({ +): SdkError => ({ error, interactionId, message: message || defaultErrorMessage.get(error) || '', From 352a9aeccd32465b865dd07ba3e93e52ae23efaa Mon Sep 17 00:00:00 2001 From: Alex Stelea Date: Fri, 26 Jul 2024 12:43:08 +0100 Subject: [PATCH 3/4] fix: retry FailedToFetch error --- .../dapp-toolkit/src/modules/gateway/gateway.module.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/dapp-toolkit/src/modules/gateway/gateway.module.ts b/packages/dapp-toolkit/src/modules/gateway/gateway.module.ts index 33e45664..75f6de9e 100644 --- a/packages/dapp-toolkit/src/modules/gateway/gateway.module.ts +++ b/packages/dapp-toolkit/src/modules/gateway/gateway.module.ts @@ -64,6 +64,15 @@ export const GatewayModule = (input: { return }) .mapErr((response) => { + if (response.reason === 'FailedToFetch') { + logger?.debug({ + error: response, + context: 'unexpected error, retrying', + }) + retry.trigger.next() + return + } + logger?.debug(response) return SdkError( 'failedToPollSubmittedTransaction', From e69c7f0b5bfa65cc4a66f52f632953fb7870920d Mon Sep 17 00:00:00 2001 From: Alex Stelea Date: Fri, 26 Jul 2024 14:13:46 +0100 Subject: [PATCH 4/4] fix: retry FailedToFetch --- .../src/modules/gateway/gateway.module.ts | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/packages/dapp-toolkit/src/modules/gateway/gateway.module.ts b/packages/dapp-toolkit/src/modules/gateway/gateway.module.ts index 75f6de9e..a6f2ae8f 100644 --- a/packages/dapp-toolkit/src/modules/gateway/gateway.module.ts +++ b/packages/dapp-toolkit/src/modules/gateway/gateway.module.ts @@ -1,6 +1,6 @@ import { GatewayApiService } from './gateway.service' import type { Result } from 'neverthrow' -import { ResultAsync, err } from 'neverthrow' +import { ResultAsync, err, ok } from 'neverthrow' import { filter, first, firstValueFrom, switchMap } from 'rxjs' import { ExponentialBackoffInput, @@ -63,27 +63,24 @@ export const GatewayModule = (input: { retry.trigger.next() return }) - .mapErr((response) => { + .orElse((response) => { if (response.reason === 'FailedToFetch') { logger?.debug({ error: response, context: 'unexpected error, retrying', }) retry.trigger.next() - return + return ok(undefined) } logger?.debug(response) - return SdkError( - 'failedToPollSubmittedTransaction', - '', - undefined, - { + return err( + SdkError('failedToPollSubmittedTransaction', '', undefined, { error: response, transactionIntentHash, context: 'GatewayModule.pollTransactionStatus.getTransactionStatus', - }, + }), ) }) }),