Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #247

Merged
merged 6 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading