hi all i use Dio Package and i got error response but i need to print the value from error response not print just error i got like this :
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>
but i want the error response print the value like this :
{
status: "error",
code: "rateLimited",
message: "bla bla bla bla bla."
}
and this is my code
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 one rror.toString(),
),
);
}
CodePudding user response:
Try doing something like this:
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);
}
}
);
}