Datastore error handler has unparsable error message
Description
While testing my Flutter app on the iOS simulator, I came across an issue. It occurred during the execution of Datastore.save, where the mutation failed due to a client error. Below is the Datastore initialization function. In this function, errorHandler is expected to return a message that can be parsed to obtain the error message.
AmplifyDataStore({
required ModelProviderInterface modelProvider,
Function(AmplifyException)? errorHandler,
DataStoreConflictHandler? conflictHandler,
List<DataStoreSyncExpression> syncExpressions = const [],
int? syncInterval,
int? syncMaxRecords,
int? syncPageSize,
AuthModeStrategy authModeStrategy = AuthModeStrategy.defaultStrategy,
})
Below is the message I am getting inside errorHandler
AmplifyDataStore(
modelProvider: ModelProvider.instance,
// Error handler for any error occurs during any datastore expression
errorHandler: (error) {
Log('Amplify Config', 'AWS Error: $error');
},
syncExpressions: syncExpression);
Message: GraphQL service returned a successful response containing errors: [Amplify.GraphQLError(message: "The conditional request failed (Service: DynamoDb, Status Code: 400, Request ID: 7083O037M1FTFRK038A4CI9H43VV4KQNSO5AEMVJF66Q9ASUAAJG)", locations: Optional([Amplify.GraphQLError.Location(line: 2, column: 3)]), path: Optional([Amplify.JSONValue.string("createTodo")]), extensions: Optional(["errorType": Amplify.JSONValue.string("Code"), "data": Amplify.JSONValue.null, "errorInfo": Amplify.JSONValue.null]))]
Recovery suggestion: The list of `GraphQLError` contains service-specific messages
Underline exception: The operation couldn’t be completed. (Amplify.GraphQLResponseError<AWSPluginsCore.MutationSync<AWSPluginsCore.AnyModel>> error 0.)
As I deep drive into the amplify_datastore iOS SDK, I noticed that the createSerializedError function below sends an error description, which complicates the process of parsing the error.
createSerializedError(error: AmplifyError) -> [String: String] {
return createSerializedError(message: error.errorDescription,
recoverySuggestion: error.recoverySuggestion,
underlyingError: error.underlyingError?.localizedDescription)
}
Error passed to flutter apps should be in either a map or a json, so that flutter client can parse the error.
Categories
- [ ] Analytics
- [ ] API (REST)
- [ ] API (GraphQL)
- [ ] Auth
- [ ] Authenticator
- [X] DataStore
- [ ] Notifications (Push)
- [ ] Storage
Steps to Reproduce
- Create models as in schema
- Initialize Datastore
- Do Datastore.save()
- Fails all incoming request in appsync or intercept iOS simulator request using any interceptor tool like Charles proxy OR Proxyman.
- Print error object in error handler
Screenshots
No response
Platforms
- [X] iOS
- [ ] Android
- [ ] Web
- [ ] macOS
- [ ] Windows
- [ ] Linux
Flutter Version
3.19.0
Amplify Flutter Version
1.7.0
Deployment Method
Amplify CLI
Schema
type Todo @model {
id: String!
message: String!
emails: [String!]!
expirationUnixTime: AWSTimestamp
}
Hi @amritnew, we are taking a look at this now and will get back to you with any updates.