onRequest method

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

Called when the request is about to be sent.

Implementation

@override
Future<void> onRequest(
    RequestOptions options, RequestInterceptorHandler handler) async {
  var intermediate = options;
  for (final interceptor in _interceptors) {
    try {
      final dynamic res = await interceptor.onRequest(intermediate);
      if (res is RequestOptions) {
        intermediate = res;
        continue;
      } else if (res is DioException) {
        handler.reject(res, false);
        return;
      }
    } on DioException catch (e) {
      handler.reject(e, false);
      return;
    } catch (e) {
      handler.reject(DioException(requestOptions: options, error: e));
      return;
    }
  }
  handler.next(intermediate);
}