onError method Null safety

  1. @override
Future onError(
  1. HasuraError error,
  2. HasuraConnect connect
)

Implementation

@override
Future onError(HasuraError error, HasuraConnect connect) async {
  bool isConnectionError = [
    'Connection Rejected',
    'Websocket Error',
  ].contains(error.message);

  isConnectionError = isConnectionError || error.message.contains('No address associated with hostname, errno = 7');

  final String key = _generateKey(error.request);
  final containsCache = await _storage.containsKey(key);
  if (isConnectionError && containsCache) {
    final cachedData = await _storage.get(key);
    return Response(
      data: cachedData,
      statusCode: 500,
      request: error.request,
    );
  }
  return error;
}