Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Datastore error handler has unparsable error message #4869

Open
2 of 14 tasks
amritnew opened this issue May 9, 2024 · 1 comment
Open
2 of 14 tasks

Datastore error handler has unparsable error message #4869

amritnew opened this issue May 9, 2024 · 1 comment
Labels
datastore Issues related to the DataStore Category feature-request A request for a new feature or an enhancement to an existing API or category.

Comments

@amritnew
Copy link

amritnew commented May 9, 2024

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
  • DataStore
  • Notifications (Push)
  • Storage

Steps to Reproduce

  1. Create models as in schema
  2. Initialize Datastore
  3. Do Datastore.save()
  4. Fails all incoming request in appsync or intercept iOS simulator request using any interceptor tool like Charles proxy OR Proxyman.
  5. Print error object in error handler

Screenshots

No response

Platforms

  • 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
}
@khatruong2009 khatruong2009 added datastore Issues related to the DataStore Category pending-triage This issue is in the backlog of issues to triage labels May 10, 2024
@khatruong2009
Copy link
Contributor

Hi @amritnew, we are taking a look at this now and will get back to you with any updates.

@NikaHsn NikaHsn added feature-request A request for a new feature or an enhancement to an existing API or category. and removed pending-triage This issue is in the backlog of issues to triage labels May 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
datastore Issues related to the DataStore Category feature-request A request for a new feature or an enhancement to an existing API or category.
Projects
None yet
Development

No branches or pull requests

3 participants