我是如何得到的错误响应在Dio包



嗨,我使用Dio包,我得到了错误响应,但我需要从错误响应中打印值,而不是打印错误我是这样的:

flutter: error:DioError [DioErrorType.response]: Http status error [400]
flutter: #0      DioMixin.assureDioError
flutter: #1      DioMixin._dispatchRequest
flutter: <asynchronous suspension>
flutter: #2      DioMixin.fetch.<anonymous closure>.<anonymous closure> (package:dio/src/dio_mixin.dart)
flutter: <asynchronous suspension>

但是我想要错误响应打印如下的值:

{
status: "error",
code: "rateLimited",
message: "bla bla bla bla bla."
}

这是我的代码

Future<void> getTechnology() async {
await DioHelper.getData(
path: 'v2/top-headlines',
query: {
'country': 'ae',
'category': 'technology',
'apiKey': '1111',
},
).then(
(value) async {
_technology = value.data['articles'];
},
).catchError(
(onError) => print(
throw onError.toString(),
),
);
}

试着这样做:

Future<void> getTechnology() async {
await DioHelper.getData(
path: 'v2/top-headlines',
query: {
'country': 'ae',
'category': 'technology',
'apiKey': '1111',
},
).then(
(value) async {
_technology = value.data['articles'];
},
).catchError(
(err) {
if (err is DioError) {
print(err.response);
}
}
);
}