Open7

(クライアント側での)GraphQL 学習スレ

miyaken12miyaken12

エラーハンドリング

こいつを使ったリクエストする際のエラーハンドリング

https://pub.dev/packages/gql_http_link/changelog

タイムアウトやインターネット接続失敗

/// Exception occurring when network fails
/// or parsed response is missing both `data` and `errors`

class ServerException extends LinkException {
  /// The parsed response
  final Response? parsedResponse;

  const ServerException({
    this.parsedResponse,
    dynamic originalException,
  }) : super(originalException);

  
  String toString() =>
      "ServerException(originalException: $originalException, parsedResponse: $parsedResponse)";
}

200系以外(厳密には300以上になってる)のエラーハンドリングは多分これ投げてくれる

/// Exception occurring when network fails
/// or parsed response is missing both `data` and `errors`.

class HttpLinkServerException extends ServerException {
  /// Response which caused the exception
  final http.Response response;

  const HttpLinkServerException({
    required this.response,
    required Response parsedResponse,
  }) : super(
          parsedResponse: parsedResponse,
        );
}