Closed xn closed 7 years ago
I think the answer is yes, we want a custom formatter for error messages, please.
Kk, leaving later today to go camping. I'll finish this out Monday or so when I get back.
@dblock Rubocop is going to complain about the method signature of #call
. I have no control over that. What should I do?
I don't know what you want to do about 0.8. Please advise.
For rubocop run rubocop -a ; rubocop --auto-gen-config
.
kk, constraining to 1.0 works, but breaks the others.
Oh I see. Make this conditional, in the case Grape::JSON
is defined you can use that, otherwise use MultiJson
, which was required in older versions of Grape.
Finally! I think this is ready to go.
This should be it.
Code looks great. You still have to add something to README!
Would this work?
class API < Grape::API
format :json
formatter :json, Grape::Formatter::ActiveModelSerializers
# Serializes errors with ActiveModel::Serializer::ErrorSerializer if an ActiveModel.
# Serializer conforms to format. ex: json, jsonapi
error_formatter :json, Grape::Formatter::ActiveModelSerializers
end
Something like that, an explain what these output.
You want me to document the behavior of ActiveModel::Serializer::ErrorSerializer
?
Yes, something should explain what's happening with this new code that wasn't happening before.
Does this work?
class API < Grape::API
format :json
formatter :json, Grape::Formatter::ActiveModelSerializers
# Serializes errors with ActiveModel::Serializer::ErrorSerializer if an ActiveModel.
# Serializer conforms to the adapter, ex: json, jsonapi.
# So an error formatted with a jsonapi formatter would render as per:
# http://jsonapi.org/format/#error-objects
error_formatter :json, Grape::Formatter::ActiveModelSerializers
end
Great! As long as there's something in the README.
That is from the readme.
Under: Tell your API to use Grape::Formatter::ActiveModelSerializers
Oh you're saying we documented it but it was never implemented (sorry, I'm just cheerleading this repo :)).
I'll just merge this, any interest in doing the next release and helping out with this project?
And thanks for hanging on with my many nitpicky comments!
No, that was a miscommunication. Let me do a quick PR for the Docs.
Would y'all be interested in having an error formatter that would allow for a jsonapi response?
If so, I can add some tests and documentation to this.