Java Code Examples for com.apollographql.apollo.api.Response#hasErrors()
The following examples show how to use
com.apollographql.apollo.api.Response#hasErrors() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ApolloExecutor.java From stream-registry with Apache License 2.0 | 5 votes |
@Override public void onResponse(@NotNull Response response) { if (response.hasErrors()) { List<com.apollographql.apollo.api.Error> errors = response.getErrors(); future.completeExceptionally(new IllegalStateException("Unexpected response: " + errors.stream().map(e -> e.getMessage()).collect(joining(", ")))); } else { future.complete(response); } }
Example 2
Source File: StreamRegistryClient.java From stream-registry with Apache License 2.0 | 5 votes |
public Response invoke(Operation operation) { Response response; if (operation instanceof Mutation) { response = executor.execute((Mutation) operation).join(); } else { response = executor.execute((Query) operation).join(); } if (response.hasErrors()) { throw new RuntimeException(((com.apollographql.apollo.api.Error) response.errors().get(0)).message()); } return response; }
Example 3
Source File: ApolloParseInterceptor.java From apollo-android with MIT License | 5 votes |
@SuppressWarnings("unchecked") InterceptorResponse parse(Operation operation, okhttp3.Response httpResponse) throws ApolloHttpException, ApolloParseException { String cacheKey = httpResponse.request().header(HttpCache.CACHE_KEY_HEADER); if (httpResponse.isSuccessful()) { try { final OperationResponseParser parser = new OperationResponseParser(operation, responseFieldMapper, scalarTypeAdapters, normalizer); final OkHttpExecutionContext httpExecutionContext = new OkHttpExecutionContext(httpResponse); Response parsedResponse = parser.parse(httpResponse.body().source()); parsedResponse = parsedResponse .toBuilder() .fromCache(httpResponse.cacheResponse() != null) .executionContext(parsedResponse.getExecutionContext().plus(httpExecutionContext)) .build(); if (parsedResponse.hasErrors() && httpCache != null) { httpCache.removeQuietly(cacheKey); } return new InterceptorResponse(httpResponse, parsedResponse, normalizer.records()); } catch (Exception rethrown) { logger.e(rethrown, "Failed to parse network response for operation: %s", operation); closeQuietly(httpResponse); if (httpCache != null) { httpCache.removeQuietly(cacheKey); } throw new ApolloParseException("Failed to parse http response", rethrown); } } else { logger.e("Failed to parse network response: %s", httpResponse); throw new ApolloHttpException(httpResponse); } }