-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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 fails to use custom errorHandler in some cases #8891
Comments
Hey @applyinnovations, DataStore only invokes the custom error handler when it encounters an AppSync mutation error. That's the current expected behavior. The custom error handler's purpose is to allow you to write business logic for handling various AppSync error scenarios and adjust the locally-persisted records accordingly. For example:
For catching client-side errors - such as field validation - we recommend using |
Hey @iartemiev, thanks for the clarification. When performing a mutation with missing fields, DataStore still creates the data locally, however does not throw the custom error handler. Wouldnt this be a prime example of when to use the error handler to remove the locally created data? |
Are you seeing a network request error in that case? |
@iartemiev There is no network error, however the network response contains a graphql error. Request Body:
Response (Status code 200) Body:
Debug logs:
As you can see in the screenshot, the local state contains the data, however the graphql server rejected the change but because our custom errorHandler provided in DataStore.configure is not used, we cannot fix the local state. |
Similar to #7860 |
On a similar note, how are we expected to handle authorisation errors? They do not throw the default handler or custom handler.
However DataStore commits the change locally and the user is unaware the mutation failed. |
@iartemiev what is the recommended method of fixing the local DataStore state in both of these scenarios? The response is thrown by the server not the client, wouldn't this be an ideal case to use the handler specified in DataStore.configure? |
I was able to reproduce the issue. Although this is currently expected behavior, I'm going to label this as a feature request that needs discussion because I do see the inconvenience in having to validate the result of the |
Thank you @chrisbonifacio for following up on this. I believe using the error handler to repair local state is an essential feature, however it is useless unless it covers all mutation events! |
We also have this issue. I can reproduce it for authorization errors (similar to that #8891 (comment)). Also, is there a default error handler in the Datastore? If I add the code below, am I overriding a default handler or just adding one? What I mean is, if I add that code it shouldn't cause any issue right?
|
@chrisbonifacio could you please give an update on this? We cannot release our new version to production until this issue is resolved |
Before opening, please confirm:
JavaScript Framework
React, React Native
Amplify APIs
DataStore
Amplify Categories
api
Environment information
Describe the bug
DataStore uses default errorHandler for some errors, and uses my custom error handler for other errors.
I have implemented a custom error handler by calling
DataStore.configure
in my app entry point (App.tsx).When submitting a DataStore.save() with a model containing invalid data:
Our AppSync API returns an error to the DataStore client and our custom error handler is used.
When submitting a DataStore.save() with an empty model:
DataStore encounters the error
Error: Field name is required
and uses the default error handler. Resulting in the following being logged to the console:[WARN] 38:37.438 DataStore - failed to execute errorHandler – Error: Field name is required
Expected behavior
The expected behaviour is to catch/route all errors to my custom errorHandler
Reproduction steps
type Model { number: Int }
DataStore.configure({ errorHandler: (error) => alert(
Custom handler ${error.message}) });
DataStore.save(new Model({ number: 1 }))
-> no errorDataStore.save(new Model({ number: "not a number" }))
-> custom error handlerDataStore.save(new Model({}))
-> default error handlerCode Snippet
Log output
aws-exports.js
No response
Manual configuration
No response
Additional configuration
No response
Mobile Device
No response
Mobile Operating System
No response
Mobile Browser
No response
Mobile Browser Version
No response
Additional information and screenshots
No response
The text was updated successfully, but these errors were encountered: