saveError method

  1. @override
Future<String> saveError(
  1. DioError error
)
override

Implementation

@override
Future<String> saveError(DioError error) {
  HttpActivity httpActivity = _activities.firstWhere(
      (data) => data.request?.requestHashCode == error.requestOptions.hashCode,
      orElse: () => HttpActivity(
          error: HttpError(
            createdAt: DateTime.now().millisecondsSinceEpoch,
            stackTrace: error.stackTrace.toString(),
            errorStatusCode: error.response?.statusCode,
            errorHashCode: error.requestOptions.hashCode,
            errorMessage: error.message,
          ),
      ));

  HttpError httpError = HttpError(
    createdAt: DateTime.now().millisecondsSinceEpoch,
    stackTrace: error.stackTrace.toString(),
    errorStatusCode: error.response?.statusCode,
    errorHashCode: error.requestOptions.hashCode,
    errorMessage: error.message,
  );
  _errors.addAll([httpError]);
  httpActivity.error = httpError;
  httpActivity.response = HttpResponse(
    responseStatusCode: error.response?.statusCode,
    responseStatusMessage: error.response?.statusMessage,
    createdAt: DateTime.now().millisecondsSinceEpoch,
    responseBody: _jsonUtil.encodeRawJson(error.response?.data),
    responseHeader: error.response?.headers.map,
  );
  _dataSubject.add(_activities);
  return Future.value('success error');
}