-
Notifications
You must be signed in to change notification settings - Fork 63
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
If no JSON API payload was found should render JSON API compliant error #80
Comments
For now I'm monkey patching and rendering a jsonapi_error when the parsing fails. Not sure if this is the correct thing to do. The docs state that we MAY return 403 and can include errors.
I feel like this should probably be configurable though |
Before rendering |
Agreed that the lib should at least raise a custom exception so that people can rescue from it with a sensible json:api error. Would you mind issuing a PR for this? |
@beauby any suggestion on how to add a if event.save
render jsonapi: event, status: :created
else
render jsonapi_errors: event.errors, status: :unprocessable_entity
end
|
Didn't see this response. I will try to come up with an elegant solution |
Maybe rather than using an exception to handle the flow control the controller should have a customizable error response. i.e. In the config file you can set the default error response hash for this situation config[:jsonapi_payload_error_hash] Then we add a hook to the controller that would call Which could look something like def jsonapi_payload_error
render_error_for_action = "jsonapi_payload_error_for_#{controller.action_name}"
return public_send(render_error_for_action) if controller.responds_to?(render_error_for_action)
render jsonapi_errors: JSONAPI::Rails.config[:jsonapi_payload_error_hash]
end What do you think @beauby |
@veelenga your question is related to this #86, it's not related to the issue outlined here. However, one note is that none of the errors attributes are actually required, they are optional
That said I think there should be a way to map these values. I will try to conceive a means of doing so |
Currently have strong params in place and when a request comes through without a compliant structure I end up raising
ActionController::ParameterMissing
because my strong params doesn't have anything to work from.How should I be handling this? Should the gem maybe handle this?
The text was updated successfully, but these errors were encountered: