Skip to content

Commit 572d2b7

Browse files
committed
Address CodeRabbitAI nitpicks
1 parent d4183a5 commit 572d2b7

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

packages/dart/lib/src/network/parse_network_retry.dart

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,14 @@ part of '../../parse_server_sdk.dart';
1414
/// Retry Conditions:
1515
///
1616
/// A request will be retried if:
17-
/// - Status code is `-1` (indicates network/parsing error, including HTML responses from proxies/load balancers)
18-
/// (HTML detection and conversion to status -1 happens in the HTTP client layer)
19-
/// - An exception is thrown during the request
17+
/// - Status code is `ParseError.otherCause` (currently -1, indicates network/parsing error,
18+
/// including HTML responses from proxies/load balancers)
19+
/// (HTML detection and conversion happens in the HTTP client layer)
20+
/// - An exception is thrown during the request (socket errors, timeouts, etc.)
2021
///
2122
/// A request will NOT be retried for:
2223
/// - Successful responses (status 200, 201)
23-
/// - Valid Parse Server errors (e.g., 101 for object not found)
24+
/// - Valid Parse Server errors (e.g., 101 for object not found, 209 for invalid session token)
2425
///
2526
/// Important Note on Non-Idempotent Methods (POST/PUT):
2627
///
@@ -52,8 +53,9 @@ part of '../../parse_server_sdk.dart';
5253
/// );
5354
/// ```
5455
///
55-
/// Note: Retries only occur on network-level failures (status -1), not on
56-
/// successful operations that return Parse error codes
56+
/// Note: Retries occur only for network-level failures (status `ParseError.otherCause`)
57+
/// or exceptions thrown by the HTTP client. Responses that return valid Parse Server
58+
/// error codes (e.g., 101, 209) are returned immediately and are not retried.
5759
///
5860
/// Example:
5961
///
@@ -99,6 +101,14 @@ Future<T> executeWithRetry<T extends ParseNetworkResponse>({
99101
);
100102
}
101103

104+
// Validate that all retry intervals are non-negative
105+
if (retryIntervals.any((interval) => interval < 0)) {
106+
throw ArgumentError(
107+
'restRetryIntervals cannot contain negative values. '
108+
'Current values: $retryIntervals',
109+
);
110+
}
111+
102112
int attemptNumber = 0;
103113
T? lastResponse;
104114

@@ -176,16 +186,16 @@ Future<T> executeWithRetry<T extends ParseNetworkResponse>({
176186
///
177187
/// Retry Triggers:
178188
///
179-
/// - Status code `-1` (network/parsing errors from the HTTP client layer)
189+
/// - Status code `ParseError.otherCause` (currently -1, network/parsing errors from the HTTP client layer)
180190
/// Note: HTML responses, socket exceptions, timeouts, and parse errors
181-
/// are converted to status -1 by the HTTP client before reaching here.
191+
/// are converted to `ParseError.otherCause` by the HTTP client before reaching here.
182192
///
183193
/// No Retry:
184194
///
185195
/// - Status code 200 or 201 (success)
186196
/// - Valid Parse Server error codes (e.g., 100-series errors)
187197
/// - These are application-level errors that won't resolve with retries
188198
bool _shouldRetryResponse(ParseNetworkResponse response) {
189-
// Retry all -1 status codes (network/parse errors, including HTML from proxies)
199+
// Retry all ParseError.otherCause status codes (network/parse errors, including HTML from proxies)
190200
return response.statusCode == ParseError.otherCause;
191201
}

0 commit comments

Comments
 (0)