You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm having trouble dealing with error responses on update.
First off, it seems that the documentation is erroneous in suggesting that an JsonApiClient::ErrorCollector object will be returned, because I'm getting an ActiveModel::Errors object instead. This isn't much of an issue, just slightly strange. Also it seems that when the error response is parsed, only the source and title fields are parsed. However the spec allows for more fields in an error object (eg. details) and I think it be good to allow customizing this behavior.
Now the main issue: on unsuccessful update of a resource, the server should respond with an errors object. However this ends up overwriting the original result set which contains included data and the like. This is troublesome as we can no longer reference associations, but this is usually needed (eg. for re-rendering the edit page for a resource, which may reference associated resources).
Currently I'm having to overwrite the update method in my BaseResource to save a copy of the last result set before making the API call, and setting the last result set to be the one before the update call, once errors have been set.
classBaseResource < JsonApiClient::Resource# overwrite update to clone the original# result set before making the API call,# otherwise the original data will be# overwritten on an error responsedefupdate(attrs={})original_result_set=last_result_set.dupsuccess=superunlesssuccessself.last_result_set=original_result_setfalseendend
Is there any other way to go about it?
The text was updated successfully, but these errors were encountered:
Yes please! Or provide a clean way to swap json_api_client's error handler for our own.
We wrote a JSON endpoint compliant with json-api spec that returns "error" objects on both validation errors and generic client/server errors (bad route, unauthenticated, server side exceptions, etc). On the client side, we want to generically collect and log all errors based on their original http status as well as custom meta information. The behavior of raising without providing original error payload gets in the way.
I'm having trouble dealing with error responses on update.
First off, it seems that the documentation is erroneous in suggesting that an
JsonApiClient::ErrorCollector
object will be returned, because I'm getting anActiveModel::Errors
object instead. This isn't much of an issue, just slightly strange. Also it seems that when the error response is parsed, only thesource
andtitle
fields are parsed. However the spec allows for more fields in an error object (eg.details
) and I think it be good to allow customizing this behavior.Now the main issue: on unsuccessful update of a resource, the server should respond with an errors object. However this ends up overwriting the original result set which contains included data and the like. This is troublesome as we can no longer reference associations, but this is usually needed (eg. for re-rendering the edit page for a resource, which may reference associated resources).
Currently I'm having to overwrite the
update
method in myBaseResource
to save a copy of the last result set before making the API call, and setting the last result set to be the one before theupdate
call, onceerrors
have been set.Is there any other way to go about it?
The text was updated successfully, but these errors were encountered: