-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
i am unable to catch dio error #1198
Comments
please make sure you are catching a DioError Object see Handling Error. |
DioError is not capturing any 400-> 500 errors |
@bagus-repository thanks but i have never used this method |
DioError is not capturing any errors, because when i'm adding headers to the options |
I had a similar problem when I migrated my app to null safety and dio from 3.0.10 to 4.0.0. After bunch of testing I found out that an I fixed it by using the
|
Hi @ApoorvaAditya Thanks for the solution. But I's still not able to catch the exceptions. I can see the exceptions go through the intercepted callbacks but after |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is still an issue, please make sure it is up to date and if so, add a comment that this is still an issue to keep it open. Thank you for your contributions. |
I found a hacky solution. We are overriding all the exceptions thrown by default. Then we are going to create custom interceptor to handle and throw exceptions. This way we can catch the DioException as we did before.
final baseOptions = BaseOptions(
baseUrl: host,
contentType: Headers.jsonContentType,
validateStatus: (int? status) {
return status != null;
// return status != null && status >= 200 && status < 300;
},
);
final dio = Dio(baseOptions);
class ErrorInterceptor extends Interceptor {
@override
void onResponse(Response response, ResponseInterceptorHandler handler) {
final status = response.statusCode;
final isValid = status != null && status >= 200 && status < 300;
if (!isValid) {
throw DioException.badResponse(
statusCode: status!,
requestOptions: response.requestOptions,
response: response,
);
}
super.onResponse(response, handler);
}
}
dio.interceptors.addAll([
ErrorInterceptor(),
]); Link to my gist https://gist.github.com/shakthizen/d644aaf19ca837a4a29a92ebad551055 |
New Issue Checklist
Issue Info
Issue Description and Steps
i used to use dio since older version
i catch errors with
now after migrating to null safety
and flutter 2.2 i cannot catch any errors i get message
any help?
The text was updated successfully, but these errors were encountered: