Skip to content

Commit 1ca1cb7

Browse files
authored
Fix broken retry logic when synchroniser is disconnected (#1035)
1 parent 6ddb3e9 commit 1ca1cb7

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

apps/common/frontend/src/contexts/LedgerApiContext.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ import { Choice, ContractId, Template, TemplateOrInterface } from '@daml/types';
1010

1111
const ANS_LEDGER_NAME = 'ans-ledger';
1212

13+
interface JsonApiErrorBody {
14+
error: string;
15+
}
16+
1317
interface JsonApiErrorResponse {
1418
status: number;
1519
statusText: string;
1620
body: JsonApiErrorBody;
1721
}
1822

19-
interface JsonApiErrorBody {
20-
error: string;
21-
}
22-
2323
export class JsonApiError extends Error {
2424
status: number;
2525
statusText: string;

apps/common/frontend/src/utils/helpers.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,13 @@ export const unitToCurrency = (unit: Unit): string => {
5353
return unitStringToCurrency(unit.toUpperCase());
5454
};
5555

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

63-
return isDomainConnectionError && failureCount < 10;
60+
return keywords.some(k => errResponse.body?.error?.includes(k));
61+
};
62+
63+
export const retrySynchronizerError = (failureCount: number, error: Error): boolean => {
64+
return isDomainConnectionError(error) && failureCount < 10;
6465
};

apps/splitwell/frontend/src/App.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
AuthProvider,
55
UserProvider,
66
theme,
7+
isDomainConnectionError,
78
PackageIdResolver,
89
JsonApiError,
910
} from '@lfdecentralizedtrust/splice-common-frontend';
@@ -60,11 +61,9 @@ const Providers: React.FC<React.PropsWithChildren> = ({ children }) => {
6061
// We only retry certain JSON API errors. Retrying everything is more confusing than helpful
6162
// because that then also retries on invalid user input.
6263
const errResponse = error as JsonApiError;
63-
const keywords = ['NOT_CONNECTED_TO_ANY_DOMAIN', 'NOT_CONNECTED_TO_DOMAIN'];
64-
const isDomainConnectionError = keywords.some(k => errResponse.body?.error?.includes(k));
6564
const is404or409 = [404, 409].includes(errResponse.status);
6665

67-
return (is404or409 || isDomainConnectionError) && failureCount < 10;
66+
return (is404or409 || isDomainConnectionError(error)) && failureCount < 10;
6867
},
6968
// Exponential backoff up to a maximum of 30 seconds
7069
retryDelay: attemptIndex => Math.min(1000 * 1.5 ** attemptIndex, 30000),

0 commit comments

Comments
 (0)