Skip to content

Commit

Permalink
✅ ++
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexV525 committed Mar 15, 2024
1 parent b9ae015 commit 834f5ee
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions dio/test/interceptor_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -318,25 +318,27 @@ void main() {
expect(response.data['errCode'], 0);
});

test('throw error on request', () async {
test('Caught exceptions before handler called', () async {
final dio = Dio();

const errorMsg = 'interceptor error';

dio.interceptors.add(InterceptorsWrapper(
onRequest: (response, handler) {
throw UnsupportedError(errorMsg);
},
));

dio.interceptors.add(
InterceptorsWrapper(
// TODO(EVERYONE): Remove the ignorance once we migrated to a higher version of Dart.
// ignore: void_checks
onRequest: (response, handler) {
throw UnsupportedError(errorMsg);
},
),
);
expect(
dio.get('https://www.cloudflare.com'),
throwsA(
isA<DioException>().having(
(dioException) => dioException.error,
'Exception',
isA<UnsupportedError>()
.having((p0) => p0.message, 'message', errorMsg)),
(dioException) => dioException.error,
'Exception',
isA<UnsupportedError>()
.having((e) => e.message, 'message', errorMsg),
),
),
);
});
Expand Down

0 comments on commit 834f5ee

Please sign in to comment.