-
Notifications
You must be signed in to change notification settings - Fork 19
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
Why does GET handle errors but POST, PATCH and DELETE do not? #239
Comments
VuexI've thought about recording error status for create/update/delete requests but haven't been sure how best to handle it. Here's why: On a given page I expect I'm generally doing one load operation, so the store has a single loading and error flag. I expect to use those for loading and error indicators in the UI displaying a list of records, for example.
Do you have thoughts on which of these approaches, or another, might work well? |
Maybe this library shouldn't be doing error handling. Maybe it should just be collecting promises and returning them. I personally would prefer that. Yes you'd have to change your tutorial but I think the implementation as it stands is flawed. Rather keep this as a pure interface to JSONAPI spec and allow the app to handle errors. For the app to handle errors though it needs to receive all promises. So any method in index.js should wrap calls to Alternately (for backwards compatibility) keep the GET mechanism as it is but certainly for the other methods it should collect and return all promises. Currently many of the actions return void, which is not conducive to error handling. |
I think that's probably the only way to go. Anything else makes the library inconsistent and limits it's use to some very specific cases. |
Here are problems as it stands:
|
Your last point about Success for all requests (all request methods) on all stores are written to the
Errors for any request would be tracked to the These two stores would be special in that they may or may not be something one wishes to persist to the back-end. |
Although I think probably all of that should be implemented as an optional extension, not as core to @reststate. I think @reststate should just return promises and provide actions for calling mutations. I.e. Each action has some mutations it runs on success and some on failure. These groups should be wrapped as actions themselves. So that if my app gets an XHR failure but decides that the reason for that failure is that the server is offline and since we're generating UUID's locally it's ok for the mutations to run anyway, that I can still run the mutations easily without a lot of manual coding. Probably this applies reststate-client, not reststate-vuex. Let me know what you think. |
FYI, this library will be unmaintained going forward. If you need new features or fixes, I recommend forking the repo and making changes, or finding an alternate library that meets your needs. |
I notice that when loading (i.e. GET) it always handles the error by catching the error and calling
handleError
. However forcreate
andupdate
it does not catch the errors. This makes it impossible to write generic code for error handling. Effectively one has to separate requests out according to method and then handle it differently depending on whether it's a GET request or not.Please can you explain why there is this difference (one might say inconsistency) in approach?
The text was updated successfully, but these errors were encountered: