assureDioError method Null safety

DioError assureDioError(
  1. dynamic err,
  2. RequestOptions requestOptions,
  3. [StackTrace? stackTrace]
)

Implementation

static DioError assureDioError(
  err,
  RequestOptions requestOptions, [
  StackTrace? stackTrace,
]) {
  DioError dioError;
  if (err is DioError) {
    dioError = err;
  } else {
    dioError = DioError(requestOptions: requestOptions, error: err);
  }

  var errorStackTrace;
  if (dioError.error is Error) {
    errorStackTrace = dioError.error.stackTrace;
  }

  dioError.stackTrace = stackTrace ??
      dioError.stackTrace ??
      errorStackTrace ??
      StackTrace.current;

  return dioError;
}