Skip to content

Commit 74b0cc2

Browse files
committed
test(dio): cover async DioException.custom propagation (cfug#1950)
After merging main, the cfug#2499 async-interceptor error zone routes uncaught async throws through assureDioException, whose DioException short-circuit preserves the propagateInnerError marker. Lock in that an async `throw DioException.custom(...)` (which hung before the merge) still unwraps to the inner type at the funnel. Signed-off-by: Meylis <[email protected]>
1 parent b3e4486 commit 74b0cc2

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

‎dio/test/interceptor_test.dart‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,6 +1168,40 @@ void main() {
11681168
},
11691169
);
11701170

1171+
test(
1172+
'async throw DioException.custom propagates inner type (interaction '
1173+
'with #2499)',
1174+
() async {
1175+
final dio = Dio()
1176+
..options.baseUrl = MockAdapter.mockBase
1177+
..httpClientAdapter = MockAdapter()
1178+
..interceptors.add(
1179+
InterceptorsWrapper(
1180+
// ignore: void_checks
1181+
onResponse: (response, handler) async {
1182+
// Async throw without ever calling the handler. The #2499
1183+
// error zone catches it and routes it through
1184+
// assureDioException, whose `is DioException` short-circuit
1185+
// preserves propagateInnerError so the inner type still
1186+
// unwraps at the funnel. (Before the main merge this hung.)
1187+
await Future<void>.value();
1188+
throw DioException.custom(
1189+
_MyApiException('async-thrown'),
1190+
requestOptions: response.requestOptions,
1191+
);
1192+
},
1193+
),
1194+
);
1195+
await expectLater(
1196+
dio.get('/test'),
1197+
throwsA(
1198+
isA<_MyApiException>()
1199+
.having((e) => e.code, 'code', 'async-thrown'),
1200+
),
1201+
);
1202+
},
1203+
);
1204+
11711205
test(
11721206
'unmarked DioException(error: customEx) still wraps (regression sentinel)',
11731207
() async {

0 commit comments

Comments
 (0)