Skip to content

Commit

Permalink
chore(datastore) ignore OperationDisabled errors in SubscriptionProce…
Browse files Browse the repository at this point in the history
…ssor (#1209)
  • Loading branch information
richardmcclellan authored Mar 17, 2021
1 parent e848465 commit 2223dfb
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -155,15 +157,15 @@ synchronized void startSubscriptions() throws DataStoreException {
}
}

private boolean isUnauthorizedException(DataStoreException exception) {
if (exception instanceof DataStoreException.GraphQLResponseException) {
List<GraphQLResponse.Error> errors = ((DataStoreException.GraphQLResponseException) exception).getErrors();
private boolean isExceptionType(DataStoreException exception, AppSyncErrorType errorType) {
if (exception instanceof GraphQLResponseException) {
List<GraphQLResponse.Error> 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;
}
Expand All @@ -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
Expand Down

0 comments on commit 2223dfb

Please sign in to comment.