onError method
Called when an exception was occurred during the request.
Implementation
@override
Future<void> onError(
DioException err, ErrorInterceptorHandler handler) async {
NetworkError? finalResult;
for (final interceptor in _interceptors.reversed) {
try {
final dynamic res = await interceptor
.onError(finalResult is DioException ? finalResult! : err);
if (res is Response) {
handler.resolve(res);
return;
}
if (res is NetworkError) {
finalResult = res;
}
} on NetworkError catch (e) {
finalResult = e;
} on DioException catch (e) {
handler.next(e);
return;
} catch (e) {
handler
.next(DioException(requestOptions: err.requestOptions, error: e));
return;
}
}
handler.next(finalResult ?? err);
}