@SuppressWarnings("unchecked") private Error readError(Map<String, Object> payload) { String message = null; final List<Error.Location> locations = new ArrayList<>(); final Map<String, Object> customAttributes = new HashMap<>(); for (Map.Entry<String, Object> entry : payload.entrySet()) { if ("message".equals(entry.getKey())) { Object value = entry.getValue(); message = value != null ? value.toString() : null; } else if ("locations".equals(entry.getKey())) { List<Map<String, Object>> locationItems = (List<Map<String, Object>>) entry.getValue(); if (locationItems != null) { for (Map<String, Object> item : locationItems) { locations.add(readErrorLocation(item)); } } } else { if (entry.getValue() != null) { customAttributes.put(entry.getKey(), entry.getValue()); } } } return new Error(message, locations, customAttributes); }
boolean isPersistedQueryNotSupported(List<Error> errors) { for (Error error : errors) { if (PROTOCOL_NEGOTIATION_ERROR_NOT_SUPPORTED.equalsIgnoreCase(error.message())) { return true; } } return false; } }
static boolean conflictPresent(Optional<Response> parsedResponse) { //Check if the parsed response contains a conflict. //The contract for conflicts is that the response will contain an error with the //string "The conditional request failed" and will contain a data element. if (parsedResponse == null || parsedResponse.get() == null || parsedResponse.get().hasErrors() == false) { return false; } Log.d(TAG, "Thread:[" + Thread.currentThread().getId() +"]: onResponse -- found error"); if ( ! parsedResponse.get().errors().get(0).toString().contains("The conditional request failed") ) { return false; } Map customAttributes = ((Error) parsedResponse.get().errors().get(0)).customAttributes(); if (customAttributes == null || customAttributes.get("data") == null ) { return false; } return true; }
@Override public void onResponse(@Nonnull ApolloInterceptor.InterceptorResponse response) { Log.v(TAG, "Thread:[" + Thread.currentThread().getId() +"]: onResponse()"); if(shouldRetry && ConflictResolutionHandler.conflictPresent(response.parsedResponse)) { //Set shouldRetry to false. Conflicts will only be attempted once. shouldRetry = false; //Found Conflict String conflictString = new JSONObject((Map)((Error) response.parsedResponse.get().errors().get(0)).customAttributes().get("data")).toString(); //Send a message to the Queue handler to retry Message message = new Message(); MutationInterceptorMessage msg = new MutationInterceptorMessage(originalMutation, currentMutation); msg.serverState = conflictString; msg.clientState = clientState; msg.requestIdentifier = recordIdentifier; msg.requestClassName = currentMutation.getClass().getSimpleName(); message.obj = msg; message.what = MessageNumberUtil.RETRY_EXEC; queueHandler.sendMessage(message); return; } //Call the customer's callback customerCallBack.onResponse(response); //Set the mutation as completed. appSyncOfflineMutationManager.setInProgressMutationAsCompleted(recordIdentifier); //Send a message to the QueueHandler to process the next mutation in queue Message message = new Message(); message.obj = new MutationInterceptorMessage(); message.what = MessageNumberUtil.SUCCESSFUL_EXEC; queueHandler.sendMessage(message); }
@Override public Object answer(InvocationOnMock invocation) throws Throwable { ((ApolloInterceptor.CallBack) invocation.getArguments()[2]).onResponse( new ApolloInterceptor.InterceptorResponse( mockHttpResponse(), com.apollographql.apollo.api.Response.<MockOperation.Data>builder(new MockOperation()) .errors(Collections.singletonList(new Error("SomeOtherError", null, null))) .build(), Collections.<Record>emptyList() ) ); return null; } }).when(chain).proceedAsync(
boolean isPersistedQueryNotFound(List<Error> errors) { for (Error error : errors) { if (PROTOCOL_NEGOTIATION_ERROR_QUERY_NOT_FOUND.equalsIgnoreCase(error.message())) { return true; } } return false; }
mockHttpResponse(), com.apollographql.apollo.api.Response.<MockOperation.Data>builder(new MockOperation()) .errors(Collections.singletonList(new Error("PersistedQueryNotFound", null, null))) .build(), Collections.<Record>emptyList()
@Test public void testUpdateWithInvalidID() { AWSAppSyncClient awsAppSyncClient = AppSyncTestSetupHelper.createAppSyncClientWithIAM(); assertNotNull(awsAppSyncClient); //Try to update a Post with a Fake ID final String updatedContent = "New content coming up @" + System.currentTimeMillis(); final String randomID = UUID.randomUUID().toString(); updatePost(awsAppSyncClient, randomID, updatedContent); assertNotNull(updatePostMutationResponse); assertNull(updatePostMutationResponse.data().updatePost()); assertNotNull(updatePostMutationResponse.errors()); Error error = updatePostMutationResponse.errors().get(0); assertNotNull(error); assertNotNull(error.message()); assertTrue(error.message().contains("Service: AmazonDynamoDBv2; Status Code: 400; Error Code: ConditionalCheckFailedException;")); }
mockHttpResponse(), com.apollographql.apollo.api.Response.<MockOperation.Data>builder(new MockOperation()) .errors(Collections.singletonList(new Error("PersistedQueryNotSupported", null, null))) .build(), Collections.<Record>emptyList()
@SuppressWarnings("unchecked") private Error readError(Map<String, Object> payload) { String message = null; final List<Error.Location> locations = new ArrayList<>(); final Map<String, Object> customAttributes = new HashMap<>(); for (Map.Entry<String, Object> entry : payload.entrySet()) { if ("message".equals(entry.getKey())) { Object value = entry.getValue(); message = value != null ? value.toString() : null; } else if ("locations".equals(entry.getKey())) { List<Map<String, Object>> locationItems = (List<Map<String, Object>>) entry.getValue(); if (locationItems != null) { for (Map<String, Object> item : locationItems) { locations.add(readErrorLocation(item)); } } } else { if (entry.getValue() != null) { customAttributes.put(entry.getKey(), entry.getValue()); } } } return new Error(message, locations, customAttributes); }
@SuppressWarnings("unchecked") private Error readError(Map<String, Object> payload) { String message = null; final List<Error.Location> locations = new ArrayList<>(); final Map<String, Object> customAttributes = new HashMap<>(); for (Map.Entry<String, Object> entry : payload.entrySet()) { if ("message".equals(entry.getKey())) { Object value = entry.getValue(); message = value != null ? value.toString() : null; } else if ("locations".equals(entry.getKey())) { List<Map<String, Object>> locationItems = (List<Map<String, Object>>) entry.getValue(); if (locationItems != null) { for (Map<String, Object> item : locationItems) { locations.add(readErrorLocation(item)); } } } else { if (entry.getValue() != null) { customAttributes.put(entry.getKey(), entry.getValue()); } } } return new Error(message, locations, customAttributes); }