onRequest method

  1. @override
void onRequest(
  1. RequestOptions options,
  2. RequestInterceptorHandler handler
)

Called when the request is about to be sent.

Implementation

@override
void onRequest(RequestOptions options, RequestInterceptorHandler handler) {
  if (_config.logRequests) {
    _logger.debug(
      'DioInterceptor: → ${options.method} ${options.uri}',
    );
  }

  // If offline and queueing is enabled, reject early so the error handler
  // can enqueue.
  if (!_monitor.isOnline && _config.queueWhenOffline) {
    handler.reject(
      DioException(
        requestOptions: options,
        type: DioExceptionType.connectionError,
        message: 'Device is offline — request will be queued',
      ),
    );
    return;
  }

  handler.next(options);
}