onError method

  1. @override
Future onError(
  1. DioError err,
  2. ErrorInterceptorHandler interceptorHandler
)

The callback will be executed on error.

If you want to continue the error , call handler.next.

If you want to complete the response with some custom data directly, you can resolve a Response object with handler.resolve and other error interceptor(s) will be skipped.

If you want to complete the response with an error message directly, you can reject a DioError object with handler.reject, and other error interceptor(s) will be skipped.

Implementation

@override
Future onError(
    DioError err, ErrorInterceptorHandler interceptorHandler) async {
  if (_shouldRetry(err)) {
    try {
      return requestRetrier.scheduleRequestRetry(err);
    } catch (e) {
      // Let any new error from the retrier pass through
      return e;
    }
  }
  // Let the error pass through if it's not the error we're looking for
  return err;
}