apply method

  1. @override
FutureOr<SentryEvent?> apply(
  1. SentryEvent event, {
  2. dynamic hint,
})

Implementation

@override
FutureOr<SentryEvent?> apply(SentryEvent event, {dynamic hint}) {
  final dynamic dioError = event.throwable;
  if (dioError is! DioError) {
    return event;
  }

  Contexts contexts = event.contexts;
  if (event.contexts.response == null) {
    contexts = contexts.copyWith(response: _responseFrom(dioError));
  }
  // Don't override just parts of the original request.
  // Keep the original one or if there's none create one.
  event = event.copyWith(
    request: event.request ?? _requestFrom(dioError),
    contexts: contexts,
  );

  final innerDioStackTrace = dioError.stackTrace;
  final innerDioErrorException = dioError.error as Object?;

  // If the inner errors stacktrace is null,
  // there's nothing to create chained exception
  if (innerDioStackTrace == null) {
    return event;
  }

  try {
    final innerException = _sentryExceptionFactory.getSentryException(
      innerDioErrorException ?? 'DioError inner stacktrace',
      stackTrace: innerDioStackTrace,
    );

    final exceptions = _removeDioErrorStackTraceFromValue(
      List<SentryException>.from(event.exceptions ?? <SentryException>[]),
      dioError,
    );

    return event.copyWith(
      exceptions: [
        innerException,
        ...exceptions,
      ],
    );
  } catch (e, stackTrace) {
    _options.logger(
      SentryLevel.debug,
      'Could not convert DioError to SentryException',
      exception: e,
      stackTrace: stackTrace,
    );
  }
  return event;
}