File tree Expand file tree Collapse file tree 2 files changed +36
-4
lines changed Expand file tree Collapse file tree 2 files changed +36
-4
lines changed Original file line number Diff line number Diff line change @@ -703,8 +703,8 @@ class Dio {
703
703
response = _makeRequest <T >(data, cancelToken);
704
704
} else {
705
705
// Otherwise, use the Future value as the request result.
706
- // If the return type is Error , we should throw it
707
- if (data is Error ) throw _assureDioError (data);
706
+ // If the return type is Exception , we should throw it
707
+ if (data is Exception ) throw _assureDioError (data);
708
708
var r = _assureResponse <T >(data);
709
709
710
710
response = r;
@@ -905,7 +905,7 @@ class Dio {
905
905
return future.then <Response <T >>((data) {
906
906
// Strictly be a DioError instance, but we relax the restrictions
907
907
// if (data is DioError)
908
- if (data is Error ) {
908
+ if (data is Exception ) {
909
909
return reject <T >(data);
910
910
}
911
911
return resolve <T >(data);
@@ -980,7 +980,7 @@ class Dio {
980
980
DioError _assureDioError (err) {
981
981
if (err is DioError ) {
982
982
return err;
983
- } else if (err is Error ) {
983
+ } else if (err is Exception ) {
984
984
err = new DioError (
985
985
response: null ,
986
986
message: err.toString (),
Original file line number Diff line number Diff line change
1
+ import 'package:dio/dio.dart' ;
2
+ import 'package:test/test.dart' ;
3
+
4
+ void main () {
5
+ test ("catch DioError" , () async {
6
+ dynamic error;
7
+
8
+ try {
9
+ await Dio ().get ("https://does.not.exist" );
10
+ fail ("did not throw" );
11
+ } on DioError catch (e) {
12
+ error = e;
13
+ }
14
+
15
+ expect (error, isNotNull);
16
+ expect (error is Exception , isTrue);
17
+ });
18
+
19
+ test ("catch DioError as Exception" , () async {
20
+ dynamic error;
21
+
22
+ try {
23
+ await Dio ().get ("https://does.not.exist" );
24
+ fail ("did not throw" );
25
+ } on Exception catch (e) {
26
+ error = e;
27
+ }
28
+
29
+ expect (error, isNotNull);
30
+ expect (error is Exception , isTrue);
31
+ });
32
+ }
You can’t perform that action at this time.
0 commit comments