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.
- Create a base client like this. You have to set validateStatus function to return
true
whatever the status code is.
final baseOptions = BaseOptions(
baseUrl: host,
contentType: Headers.jsonContentType,
validateStatus: (int? status) {
return status != null;
// return status != null && status >= 200 && status < 300;