Skip to content

Commit 2223dfb

Browse files
chore(datastore) ignore OperationDisabled errors in SubscriptionProcessor (#1209)
1 parent e848465 commit 2223dfb

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

aws-datastore/src/main/java/com/amplifyframework/datastore/appsync/AppSyncExtensions.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,13 @@ public enum AppSyncErrorType {
144144
*/
145145
CONFLICT_UNHANDLED("ConflictUnhandled"),
146146

147+
/**
148+
* This error is not for general use unless you have consulted directly with AWS. When DataStore encounters
149+
* this error, it will ignore the error and allow DataStore to continue running. This error is subject to be
150+
* deprecated/removed in the future.
151+
*/
152+
OPERATION_DISABLED("OperationDisabled"),
153+
147154
/**
148155
* An Unauthorized error will occur if the provided credentials are not authorized for the requested operation.
149156
*/

aws-datastore/src/main/java/com/amplifyframework/datastore/syncengine/SubscriptionProcessor.java

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,10 @@
3232
import com.amplifyframework.datastore.AmplifyDisposables;
3333
import com.amplifyframework.datastore.DataStoreChannelEventName;
3434
import com.amplifyframework.datastore.DataStoreException;
35+
import com.amplifyframework.datastore.DataStoreException.GraphQLResponseException;
3536
import com.amplifyframework.datastore.appsync.AppSync;
3637
import com.amplifyframework.datastore.appsync.AppSyncExtensions;
38+
import com.amplifyframework.datastore.appsync.AppSyncExtensions.AppSyncErrorType;
3739
import com.amplifyframework.datastore.appsync.ModelWithMetadata;
3840
import com.amplifyframework.datastore.appsync.SerializedModel;
3941
import com.amplifyframework.hub.HubChannel;
@@ -155,15 +157,15 @@ synchronized void startSubscriptions() throws DataStoreException {
155157
}
156158
}
157159

158-
private boolean isUnauthorizedException(DataStoreException exception) {
159-
if (exception instanceof DataStoreException.GraphQLResponseException) {
160-
List<GraphQLResponse.Error> errors = ((DataStoreException.GraphQLResponseException) exception).getErrors();
160+
private boolean isExceptionType(DataStoreException exception, AppSyncErrorType errorType) {
161+
if (exception instanceof GraphQLResponseException) {
162+
List<GraphQLResponse.Error> errors = ((GraphQLResponseException) exception).getErrors();
161163
GraphQLResponse.Error firstError = errors.get(0);
162164
if (Empty.check(firstError.getExtensions())) {
163165
return false;
164166
}
165167
AppSyncExtensions extensions = new AppSyncExtensions(firstError.getExtensions());
166-
return AppSyncExtensions.AppSyncErrorType.UNAUTHORIZED.equals(extensions.getErrorType());
168+
return errorType.equals(extensions.getErrorType());
167169
}
168170
return false;
169171
}
@@ -186,11 +188,17 @@ private boolean isUnauthorizedException(DataStoreException exception) {
186188
},
187189
emitter::onNext,
188190
dataStoreException -> {
189-
// Ignore Unauthorized errors, so that DataStore can still be used even if the user is only
190-
// authorized to read a subset of the models.
191-
if (isUnauthorizedException(dataStoreException)) {
191+
if (isExceptionType(dataStoreException, AppSyncErrorType.UNAUTHORIZED)) {
192+
// Ignore Unauthorized errors, so that DataStore can still be used even if the user is only
193+
// authorized to read a subset of the models.
192194
latch.countDown();
193-
LOG.warn("Unauthorized failure for " + subscriptionType.name() + " " + modelSchema.getName());
195+
LOG.warn("Unauthorized failure:" + subscriptionType.name() + " " + modelSchema.getName());
196+
} else if (isExceptionType(dataStoreException, AppSyncErrorType.OPERATION_DISABLED)) {
197+
// Ignore OperationDisabled errors, so that DataStore can be used even without subscriptions.
198+
// This logic is only in place to address a specific use case, and should not be used without
199+
// unless you have consulted with AWS. It is subject to be deprecated/removed in the future.
200+
latch.countDown();
201+
LOG.warn("Operation disabled:" + subscriptionType.name() + " " + modelSchema.getName());
194202
} else {
195203
if (latch.getCount() > 0) {
196204
// An error occurred during startup. Abort and notify the Orchestrator by throwing the

0 commit comments

Comments
 (0)