@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 { OperationResponseParser parser = new OperationResponseParser(operation, responseFieldMapper, scalarTypeAdapters, normalizer); Response parsedResponse = parser.parse(httpResponse.body().source()) .toBuilder() .fromCache(httpResponse.cacheResponse() != null) .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); } }
@Override public void onResponse(@Nonnull InterceptorResponse response) { callBack.onResponse(response); if ( callbackForPersistentMutation != null) { JSONObject jsonObject; try { jsonObject = new JSONObject(response.clonedBufferString.get()); callbackForPersistentMutation.onResponse(new PersistentMutationsResponse( jsonObject.getJSONObject("data"), jsonObject.getJSONArray("errors"), request.operation.getClass().getSimpleName(), object.recordIdentifier)); } catch (Exception e) { callbackForPersistentMutation.onFailure(new PersistentMutationsError( request.operation.getClass().getSimpleName(), object.recordIdentifier, new ApolloParseException(e.getLocalizedMessage())) ); } } appSyncOfflineMutationManager.setInProgressPersistentMutationAsCompleted(object.recordIdentifier); queueHandler.clearInMemoryOfflineMutationObjectBeingExecuted(); queueHandler.clearPersistentOfflineMutationObjectBeingExecuted(); queueHandler.sendEmptyMessage(MessageNumberUtil.SUCCESSFUL_EXEC); }
public void onMessage(final String msg) { try { //TODO: Check why is this being converted to a Response Body ResponseBody messageBody = ResponseBody.create(MediaType.parse("text/plain"), msg); OperationResponseParser<D, T> parser = new OperationResponseParser(subscription, subscription.responseFieldMapper(), scalarTypeAdapters, normalizer); Response<T> parsedResponse = parser.parse(messageBody.source()); if (parsedResponse.hasErrors()) { Log.w(TAG, "Errors detected in parsed subscription message"); } //TODO: Check why the message is this is not done in an else clause propagateMessageToAllListeners(parsedResponse); } catch (Exception rethrown) { Log.e(TAG, "Failed to parse: " + msg, rethrown); notifyErrorToAllListeners(new ApolloParseException("Failed to parse http response", rethrown)); } }
httpCache.removeQuietly(cacheKey); throw new ApolloParseException("Failed to parse http response", rethrown);
httpCache.removeQuietly(cacheKey); throw new ApolloParseException("Failed to parse http response", rethrown);