Skip to content

Commit

Permalink
Merge pull request #247 from radixdlt/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
xstelea authored Jul 26, 2024
2 parents 6683d23 + e69c7f0 commit 2309d51
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 7 deletions.
1 change: 0 additions & 1 deletion examples/simple-dapp/public/.well-known/radix.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"callbackPath": "/connect",
"dApps": [
{
"dAppDefinitionAddress": "account_tdx_2_12yf9gd53yfep7a669fv2t3wm7nz9zeezwd04n02a433ker8vza6rhe"
Expand Down
11 changes: 9 additions & 2 deletions packages/dapp-toolkit/src/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,21 @@ const defaultErrorMessage = new Map<string, string>()
.set(ErrorType.rejectedByUser, 'user rejected request')
.set(ErrorType.canceledByUser, 'user has canceled the request')

export type SdkError = ReturnType<typeof SdkError>
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) || '',
jsError,
})
33 changes: 29 additions & 4 deletions packages/dapp-toolkit/src/modules/gateway/gateway.module.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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}`)

Expand All @@ -54,9 +63,25 @@ 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 ok(undefined)
}

logger?.debug(response)
return SdkError('failedToPollSubmittedTransaction', '')
return err(
SdkError('failedToPollSubmittedTransaction', '', undefined, {
error: response,
transactionIntentHash,
context:
'GatewayModule.pollTransactionStatus.getTransactionStatus',
}),
)
})
}),
filter(
Expand Down

0 comments on commit 2309d51

Please sign in to comment.