onError method
Intercepts API request errors and retries if applicable.
If the error is a connection error (SocketException
), it schedules a retry attempt.
If the retry is successful, it resolves the request with the new response.
Otherwise, it propagates the error to the next handler.
Implementation
@override
void onError(DioException err, ErrorInterceptorHandler handler) async {
if (_shouldRetry(err)) {
try {
var response = await requestRetrier.scheduleRequestRetry(err.requestOptions);
return handler.resolve(response);
} catch (e) {
return super.onError(err, handler);
}
}
return super.onError(err, handler);
}