Skip to content

Commit ab0bc23

Browse files
committed
refactor(dio): rename to rejectCustom/isCustom per review; restore cfug#1950 changelog
Address @kuhnroyal's naming review on cfug#2514 for consistency with the DioException.custom factory: - rejectCustomError -> rejectCustom (all three interceptor handlers) - propagateInnerError -> isCustom (field, constructor, copyWith) Also restore the cfug#1950 CHANGELOG 'Unreleased' entry that was dropped in an earlier main merge.
1 parent 2754e17 commit ab0bc23

6 files changed

Lines changed: 33 additions & 33 deletions

File tree

‎dio/CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ See the [Migration Guide][] for the complete breaking changes list.**
1111
On web, timeout handling is best-effort because synchronous JavaScript work cannot be preempted.
1212
- Fix `FormData.clone()` dropping `boundaryName` and `camelCaseContentDisposition`, so a retried multipart request now keeps the original options instead of silently falling back to the defaults.
1313
- Fix `QueuedInterceptor` stalling its queue forever when the active request is cancelled while its callback is still pending (never calls `next`/`resolve`/`reject`), which blocked every subsequent request routed through the interceptor.
14+
- Add an opt-in way for interceptors to propagate a custom exception type to the caller via `DioException.custom(...)` and `handler.rejectCustom(...)`, so `on MyException catch (e)` matches at the await boundary instead of always seeing `DioException`.
1415

1516
## 5.9.2
1617

‎dio/README.md‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -541,15 +541,15 @@ By default, `dio` wraps any exception thrown from an interceptor inside a
541541
`DioException`, so callers always see `DioException` at the await boundary.
542542
If you want callers to be able to `catch` your own exception type
543543
directly, opt in via `DioException.custom(...)` or
544-
`handler.rejectCustomError(...)`:
544+
`handler.rejectCustom(...)`:
545545

546546
```dart
547547
class UnauthorizedException implements Exception {}
548548
549549
dio.interceptors.add(InterceptorsWrapper(
550550
onResponse: (response, handler) {
551551
if (response.statusCode == 401) {
552-
handler.rejectCustomError(
552+
handler.rejectCustom(
553553
UnauthorizedException(),
554554
response.requestOptions,
555555
);
@@ -677,8 +677,8 @@ String? message;
677677
678678
/// When `true`, the request pipeline rethrows [error] verbatim at its
679679
/// final boundary instead of throwing this `DioException`. Set by
680-
/// [DioException.custom] / `handler.rejectCustomError`. Defaults to `false`.
681-
bool propagateInnerError;
680+
/// [DioException.custom] / `handler.rejectCustom`. Defaults to `false`.
681+
bool isCustom;
682682
```
683683

684684
### DioExceptionType

‎dio/lib/src/dio_exception.dart‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class DioException implements Exception {
7979
this.error,
8080
StackTrace? stackTrace,
8181
this.message,
82-
this.propagateInnerError = false,
82+
this.isCustom = false,
8383
}) : stackTrace = identical(stackTrace, StackTrace.empty)
8484
? requestOptions.sourceStackTrace ?? StackTrace.current
8585
: stackTrace ??
@@ -257,7 +257,7 @@ class DioException implements Exception {
257257
error: error,
258258
stackTrace: stackTrace,
259259
message: message,
260-
propagateInnerError: true,
260+
isCustom: true,
261261
);
262262

263263
/// The request info for the request that throws exception.
@@ -288,12 +288,12 @@ class DioException implements Exception {
288288
/// preserving its runtime type for the caller.
289289
///
290290
/// Set automatically by [DioException.custom] and by the
291-
/// `rejectCustomError(...)` helpers on interceptor handlers. Defaults
291+
/// `rejectCustom(...)` helpers on interceptor handlers. Defaults
292292
/// to `false` for all other constructors and factories — existing
293293
/// behavior is unchanged.
294294
///
295295
/// Resolves https://github.com/cfug/dio/issues/1950.
296-
final bool propagateInnerError;
296+
final bool isCustom;
297297

298298
/// Users can customize the content of [toString] when thrown.
299299
static DioExceptionReadableStringBuilder readableStringBuilder =
@@ -311,7 +311,7 @@ class DioException implements Exception {
311311
Object? error,
312312
StackTrace? stackTrace,
313313
String? message,
314-
bool? propagateInnerError,
314+
bool? isCustom,
315315
}) {
316316
return DioException(
317317
requestOptions: requestOptions ?? this.requestOptions,
@@ -320,7 +320,7 @@ class DioException implements Exception {
320320
error: error ?? this.error,
321321
stackTrace: stackTrace ?? this.stackTrace,
322322
message: message ?? this.message,
323-
propagateInnerError: propagateInnerError ?? this.propagateInnerError,
323+
isCustom: isCustom ?? this.isCustom,
324324
);
325325
}
326326

‎dio/lib/src/dio_mixin.dart‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -566,10 +566,10 @@ abstract class DioMixin implements Dio {
566566
requestOptions,
567567
);
568568
// If the exception was constructed via [DioException.custom] or
569-
// `handler.rejectCustomError(...)`, propagate the inner error
569+
// `handler.rejectCustom(...)`, propagate the inner error
570570
// verbatim so callers can `on MyException catch (e)` directly.
571571
// Resolves https://github.com/cfug/dio/issues/1950.
572-
if (dioException.propagateInnerError && dioException.error != null) {
572+
if (dioException.isCustom && dioException.error != null) {
573573
Error.throwWithStackTrace(
574574
dioException.error!,
575575
dioException.stackTrace,

‎dio/lib/src/interceptor.dart‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ class RequestInterceptorHandler extends _BaseHandler {
107107
/// See [DioException.custom] for details.
108108
///
109109
/// Resolves https://github.com/cfug/dio/issues/1950.
110-
void rejectCustomError(
110+
void rejectCustom(
111111
Object error,
112112
RequestOptions requestOptions, [
113113
bool callFollowingErrorInterceptor = false,
@@ -169,8 +169,8 @@ class ResponseInterceptorHandler extends _BaseHandler {
169169
_processNextInQueue?.call();
170170
}
171171

172-
/// See [RequestInterceptorHandler.rejectCustomError].
173-
void rejectCustomError(
172+
/// See [RequestInterceptorHandler.rejectCustom].
173+
void rejectCustom(
174174
Object error,
175175
RequestOptions requestOptions, [
176176
bool callFollowingErrorInterceptor = false,
@@ -219,8 +219,8 @@ class ErrorInterceptorHandler extends _BaseHandler {
219219
_processNextInQueue?.call();
220220
}
221221

222-
/// See [RequestInterceptorHandler.rejectCustomError].
223-
void rejectCustomError(
222+
/// See [RequestInterceptorHandler.rejectCustom].
223+
void rejectCustom(
224224
Object error,
225225
RequestOptions requestOptions,
226226
) {

‎dio/test/interceptor_test.dart‎

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,15 +1068,15 @@ void main() {
10681068

10691069
group('Custom exception unwrapping (#1950)', () {
10701070
test(
1071-
'handler.rejectCustomError from onResponse propagates inner type',
1071+
'handler.rejectCustom from onResponse propagates inner type',
10721072
() async {
10731073
final dio = Dio()
10741074
..options.baseUrl = MockAdapter.mockBase
10751075
..httpClientAdapter = MockAdapter()
10761076
..interceptors.add(
10771077
InterceptorsWrapper(
10781078
onResponse: (response, handler) {
1079-
handler.rejectCustomError(
1079+
handler.rejectCustom(
10801080
_MyApiException('unauthorized'),
10811081
response.requestOptions,
10821082
);
@@ -1094,15 +1094,15 @@ void main() {
10941094
);
10951095

10961096
test(
1097-
'handler.rejectCustomError from onRequest propagates inner type',
1097+
'handler.rejectCustom from onRequest propagates inner type',
10981098
() async {
10991099
final dio = Dio()
11001100
..options.baseUrl = MockAdapter.mockBase
11011101
..httpClientAdapter = MockAdapter()
11021102
..interceptors.add(
11031103
InterceptorsWrapper(
11041104
onRequest: (options, handler) {
1105-
handler.rejectCustomError(_MyApiException('blocked'), options);
1105+
handler.rejectCustom(_MyApiException('blocked'), options);
11061106
},
11071107
),
11081108
);
@@ -1116,15 +1116,15 @@ void main() {
11161116
);
11171117

11181118
test(
1119-
'handler.rejectCustomError from onError propagates inner type',
1119+
'handler.rejectCustom from onError propagates inner type',
11201120
() async {
11211121
final dio = Dio()
11221122
..options.baseUrl = MockAdapter.mockBase
11231123
..httpClientAdapter = MockAdapter()
11241124
..interceptors.add(
11251125
InterceptorsWrapper(
11261126
onError: (err, handler) {
1127-
handler.rejectCustomError(
1127+
handler.rejectCustom(
11281128
_MyApiException('server-down'),
11291129
err.requestOptions,
11301130
);
@@ -1182,7 +1182,7 @@ void main() {
11821182
// Async throw without ever calling the handler. The #2499
11831183
// error zone catches it and routes it through
11841184
// assureDioException, whose `is DioException` short-circuit
1185-
// preserves propagateInnerError so the inner type still
1185+
// preserves isCustom so the inner type still
11861186
// unwraps at the funnel. (Before the main merge this hung.)
11871187
await Future<void>.value();
11881188
throw DioException.custom(
@@ -1234,15 +1234,15 @@ void main() {
12341234
);
12351235

12361236
test(
1237-
'copyWith preserves propagateInnerError through onError chain',
1237+
'copyWith preserves isCustom through onError chain',
12381238
() async {
12391239
final dio = Dio()
12401240
..options.baseUrl = MockAdapter.mockBase
12411241
..httpClientAdapter = MockAdapter()
12421242
..interceptors.add(
12431243
InterceptorsWrapper(
12441244
onResponse: (response, handler) {
1245-
handler.rejectCustomError(
1245+
handler.rejectCustom(
12461246
_MyApiException('original'),
12471247
response.requestOptions,
12481248
true, // callFollowingErrorInterceptor
@@ -1263,14 +1263,14 @@ void main() {
12631263
},
12641264
);
12651265

1266-
test('rejectCustomError works inside QueuedInterceptor', () async {
1266+
test('rejectCustom works inside QueuedInterceptor', () async {
12671267
final dio = Dio()
12681268
..options.baseUrl = MockAdapter.mockBase
12691269
..httpClientAdapter = MockAdapter()
12701270
..interceptors.add(
12711271
QueuedInterceptorsWrapper(
12721272
onResponse: (response, handler) {
1273-
handler.rejectCustomError(
1273+
handler.rejectCustom(
12741274
_MyApiException('queued'),
12751275
response.requestOptions,
12761276
);
@@ -1285,20 +1285,19 @@ void main() {
12851285
);
12861286
});
12871287

1288-
test('DioException.custom factory sets propagateInnerError', () {
1288+
test('DioException.custom factory sets isCustom', () {
12891289
final ex = DioException.custom(
12901290
_MyApiException('x'),
12911291
requestOptions: RequestOptions(),
12921292
);
1293-
expect(ex.propagateInnerError, isTrue);
1293+
expect(ex.isCustom, isTrue);
12941294
expect(ex.error, isA<_MyApiException>());
12951295
expect(ex.type, DioExceptionType.unknown);
12961296
});
12971297

1298-
test('DioException default constructor leaves propagateInnerError false',
1299-
() {
1298+
test('DioException default constructor leaves isCustom false', () {
13001299
final ex = DioException(requestOptions: RequestOptions());
1301-
expect(ex.propagateInnerError, isFalse);
1300+
expect(ex.isCustom, isFalse);
13021301
});
13031302
});
13041303

0 commit comments

Comments
 (0)