From 2223dfb799377aab81aa316ea49956908df77d7d Mon Sep 17 00:00:00 2001 From: Richard McClellan Date: Wed, 17 Mar 2021 11:21:18 -0500 Subject: [PATCH] chore(datastore) ignore OperationDisabled errors in SubscriptionProcessor (#1209) --- .../datastore/appsync/AppSyncExtensions.java | 7 ++++++ .../syncengine/SubscriptionProcessor.java | 24 ++++++++++++------- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/aws-datastore/src/main/java/com/amplifyframework/datastore/appsync/AppSyncExtensions.java b/aws-datastore/src/main/java/com/amplifyframework/datastore/appsync/AppSyncExtensions.java index 921ffddf2c..c307927668 100644 --- a/aws-datastore/src/main/java/com/amplifyframework/datastore/appsync/AppSyncExtensions.java +++ b/aws-datastore/src/main/java/com/amplifyframework/datastore/appsync/AppSyncExtensions.java @@ -144,6 +144,13 @@ public enum AppSyncErrorType { */ CONFLICT_UNHANDLED("ConflictUnhandled"), + /** + * This error is not for general use unless you have consulted directly with AWS. When DataStore encounters + * this error, it will ignore the error and allow DataStore to continue running. This error is subject to be + * deprecated/removed in the future. + */ + OPERATION_DISABLED("OperationDisabled"), + /** * An Unauthorized error will occur if the provided credentials are not authorized for the requested operation. */ diff --git a/aws-datastore/src/main/java/com/amplifyframework/datastore/syncengine/SubscriptionProcessor.java b/aws-datastore/src/main/java/com/amplifyframework/datastore/syncengine/SubscriptionProcessor.java index 1f540db36e..c76839a45e 100644 --- a/aws-datastore/src/main/java/com/amplifyframework/datastore/syncengine/SubscriptionProcessor.java +++ b/aws-datastore/src/main/java/com/amplifyframework/datastore/syncengine/SubscriptionProcessor.java @@ -32,8 +32,10 @@ import com.amplifyframework.datastore.AmplifyDisposables; import com.amplifyframework.datastore.DataStoreChannelEventName; import com.amplifyframework.datastore.DataStoreException; +import com.amplifyframework.datastore.DataStoreException.GraphQLResponseException; import com.amplifyframework.datastore.appsync.AppSync; import com.amplifyframework.datastore.appsync.AppSyncExtensions; +import com.amplifyframework.datastore.appsync.AppSyncExtensions.AppSyncErrorType; import com.amplifyframework.datastore.appsync.ModelWithMetadata; import com.amplifyframework.datastore.appsync.SerializedModel; import com.amplifyframework.hub.HubChannel; @@ -155,15 +157,15 @@ synchronized void startSubscriptions() throws DataStoreException { } } - private boolean isUnauthorizedException(DataStoreException exception) { - if (exception instanceof DataStoreException.GraphQLResponseException) { - List errors = ((DataStoreException.GraphQLResponseException) exception).getErrors(); + private boolean isExceptionType(DataStoreException exception, AppSyncErrorType errorType) { + if (exception instanceof GraphQLResponseException) { + List errors = ((GraphQLResponseException) exception).getErrors(); GraphQLResponse.Error firstError = errors.get(0); if (Empty.check(firstError.getExtensions())) { return false; } AppSyncExtensions extensions = new AppSyncExtensions(firstError.getExtensions()); - return AppSyncExtensions.AppSyncErrorType.UNAUTHORIZED.equals(extensions.getErrorType()); + return errorType.equals(extensions.getErrorType()); } return false; } @@ -186,11 +188,17 @@ private boolean isUnauthorizedException(DataStoreException exception) { }, emitter::onNext, dataStoreException -> { - // Ignore Unauthorized errors, so that DataStore can still be used even if the user is only - // authorized to read a subset of the models. - if (isUnauthorizedException(dataStoreException)) { + if (isExceptionType(dataStoreException, AppSyncErrorType.UNAUTHORIZED)) { + // Ignore Unauthorized errors, so that DataStore can still be used even if the user is only + // authorized to read a subset of the models. latch.countDown(); - LOG.warn("Unauthorized failure for " + subscriptionType.name() + " " + modelSchema.getName()); + LOG.warn("Unauthorized failure:" + subscriptionType.name() + " " + modelSchema.getName()); + } else if (isExceptionType(dataStoreException, AppSyncErrorType.OPERATION_DISABLED)) { + // Ignore OperationDisabled errors, so that DataStore can be used even without subscriptions. + // This logic is only in place to address a specific use case, and should not be used without + // unless you have consulted with AWS. It is subject to be deprecated/removed in the future. + latch.countDown(); + LOG.warn("Operation disabled:" + subscriptionType.name() + " " + modelSchema.getName()); } else { if (latch.getCount() > 0) { // An error occurred during startup. Abort and notify the Orchestrator by throwing the