Skip to content
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
8 changes: 4 additions & 4 deletions apps/common/frontend/src/contexts/LedgerApiContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ import { Choice, ContractId, Template, TemplateOrInterface } from '@daml/types';

const ANS_LEDGER_NAME = 'ans-ledger';

interface JsonApiErrorBody {
error: string;
}

interface JsonApiErrorResponse {
status: number;
statusText: string;
body: JsonApiErrorBody;
}

interface JsonApiErrorBody {
error: string;
}

export class JsonApiError extends Error {
status: number;
statusText: string;
Expand Down
11 changes: 6 additions & 5 deletions apps/common/frontend/src/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,13 @@ export const unitToCurrency = (unit: Unit): string => {
return unitStringToCurrency(unit.toUpperCase());
};

export const retrySynchronizerError = (failureCount: number, error: Error): boolean => {
// We only retry certain JSON API errors. Retrying everything is more confusing than helpful
// because that then also retries on invalid user input.
export const isDomainConnectionError: (error: Error) => boolean = (error: Error) => {
const errResponse = error as JsonApiError;
const keywords = ['NOT_CONNECTED_TO_SYNCHRONIZER', 'NOT_CONNECTED_TO_ANY_SYNCHRONIZER'];
const isDomainConnectionError = keywords.some(k => errResponse.body?.error?.includes(k));

return isDomainConnectionError && failureCount < 10;
return keywords.some(k => errResponse.body?.error?.includes(k));
};

export const retrySynchronizerError = (failureCount: number, error: Error): boolean => {
return isDomainConnectionError(error) && failureCount < 10;
};
5 changes: 2 additions & 3 deletions apps/splitwell/frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
AuthProvider,
UserProvider,
theme,
isDomainConnectionError,
PackageIdResolver,
JsonApiError,
} from '@lfdecentralizedtrust/splice-common-frontend';
Expand Down Expand Up @@ -60,11 +61,9 @@ const Providers: React.FC<React.PropsWithChildren> = ({ children }) => {
// We only retry certain JSON API errors. Retrying everything is more confusing than helpful
// because that then also retries on invalid user input.
const errResponse = error as JsonApiError;
const keywords = ['NOT_CONNECTED_TO_ANY_DOMAIN', 'NOT_CONNECTED_TO_DOMAIN'];
Copy link
Contributor Author

@fayi-da fayi-da Jun 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the crux of this change. The rest is cleanup + more specific types

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:D Took me a while to see (DOMAIN->SYNCHRONIZER)... Good catch!

const isDomainConnectionError = keywords.some(k => errResponse.body?.error?.includes(k));
const is404or409 = [404, 409].includes(errResponse.status);

return (is404or409 || isDomainConnectionError) && failureCount < 10;
return (is404or409 || isDomainConnectionError(error)) && failureCount < 10;
},
// Exponential backoff up to a maximum of 30 seconds
retryDelay: attemptIndex => Math.min(1000 * 1.5 ** attemptIndex, 30000),
Expand Down
Loading