Skip to content

Commit 08c0925

Browse files
authored
Handle exceptional errors when retrying connections (#676)
1 parent e487963 commit 08c0925

File tree

4 files changed

+871
-159
lines changed

4 files changed

+871
-159
lines changed

src/__fixtures__/errors.ts

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import { Code, ConnectError } from '@connectrpc/connect';
2+
3+
// Non-retryable ConnectError codes
4+
export const unauthenticatedError = new ConnectError(
5+
'User is not authenticated',
6+
Code.Unauthenticated
7+
);
8+
9+
export const permissionDeniedError = new ConnectError(
10+
'Permission denied to access resource',
11+
Code.PermissionDenied
12+
);
13+
14+
export const invalidArgumentError = new ConnectError(
15+
'Invalid argument provided',
16+
Code.InvalidArgument
17+
);
18+
19+
export const notFoundError = new ConnectError(
20+
'Resource not found',
21+
Code.NotFound
22+
);
23+
24+
export const failedPreconditionError = new ConnectError(
25+
'Failed precondition check',
26+
Code.FailedPrecondition
27+
);
28+
29+
export const outOfRangeError = new ConnectError(
30+
'Value out of range',
31+
Code.OutOfRange
32+
);
33+
34+
export const unimplementedError = new ConnectError(
35+
'Method not implemented',
36+
Code.Unimplemented
37+
);
38+
39+
export const alreadyExistsError = new ConnectError(
40+
'Resource already exists',
41+
Code.AlreadyExists
42+
);
43+
44+
export const canceledError = new ConnectError(
45+
'Operation was canceled',
46+
Code.Canceled
47+
);
48+
49+
// Retryable ConnectError codes
50+
export const unavailableError = new ConnectError(
51+
'Service unavailable',
52+
Code.Unavailable
53+
);
54+
55+
export const deadlineExceededError = new ConnectError(
56+
'Deadline exceeded',
57+
Code.DeadlineExceeded
58+
);
59+
60+
export const abortedError = new ConnectError('Operation aborted', Code.Aborted);
61+
62+
export const internalError = new ConnectError(
63+
'Internal server error',
64+
Code.Internal
65+
);
66+
67+
export const unknownError = new ConnectError(
68+
'Unknown error occurred',
69+
Code.Unknown
70+
);
71+
72+
// Non-retryable standard errors
73+
export const configurationError = new Error('Invalid configuration provided');
74+
75+
export const cannotDialError = new Error(
76+
'cannot dial "example.com" directly, please use a local url instead.'
77+
);
78+
79+
// Retryable standard errors
80+
export const networkError = new Error('Network connection failed');
81+
82+
export const timeoutError = new Error('Connection timed out');

src/robot/__fixtures__/dial-configs.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,13 @@ export const withNoReconnect: DialConf = {
1818
...baseDialConfig,
1919
noReconnect: true,
2020
} as const;
21+
22+
export const withRetry: DialConf = {
23+
...baseDialConfig,
24+
noReconnect: false,
25+
reconnectMaxAttempts: 3,
26+
} as const;
27+
28+
export const TEST_DIAL_TIMEOUT_MS = 1000;
29+
export const TEST_MAX_RETRY_ATTEMPTS = 5;
30+
export const TEST_TIMER_ADVANCE_MS = 100;

0 commit comments

Comments
 (0)