onError method
Called when an exception was occurred during the request.
Implementation
@override
void onError(
DioException err,
ErrorInterceptorHandler handler,
) async {
final cacheOptions = _getCacheOptions(err.requestOptions);
if (_shouldSkip(err.requestOptions, options: cacheOptions, error: err)) {
handler.next(err);
return;
}
if (_isCacheCheckAllowed(err.response, cacheOptions)) {
// Retrieve response from cache
final cacheResponse = await _loadResponse(err.requestOptions);
if (err.response != null && cacheResponse != null) {
// Update cache response with response header values
await _saveResponse(
cacheResponse..updateCacheHeaders(err.response),
cacheOptions,
statusCode: err.response?.statusCode,
);
}
// Resolve with found cached response
if (cacheResponse != null) {
handler.resolve(cacheResponse);
return;
}
}
handler.next(err);
}