-
Notifications
You must be signed in to change notification settings - Fork 88
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
Add a to_json method for Granite::Error #401
Conversation
What is this actually needed for? |
I found it useful for quickly and easily returning validation errors. post = Post.new
post.save
if post.errors.size > 0
post.errors.to_json
end Like I said, wasn't sure if this was wanted or not. I use it in my codebase so I thought I'd send a PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💯 Can you add a small test to verify?
@drujensen for some reason I can't run tests on my local machine. Still, I'm not sure how I would test it. Just write a test that makes sure the json is valid? |
Correct. You can test just the Error class. Something like (pseudo code):
|
thanks! |
I wasn't sure if this was something that was at all wanted, so I figured I'd send a PR to be safe.
This PR manually defines a
to_json
method forGranite::Error
. We can'tinclude JSON::Serializable
due to the type ofGranite::Error.field
, so a manual solution is required.