Sunday, October 28, 2012

Re: [Rails] JSON response , error message



On Sunday, 28 October 2012 02:07:27 UTC-4, Jordon Bedwell wrote:
On Sun, Oct 28, 2012 at 12:26 AM, Saravanan P
<sarav...@shriramits.com> wrote:
> render :json => { :errors => @example.errors.full_messages }, :status => 422

Why are you sending a 422?  If you really want to stick in the 400
range it would be more suitable to send a 409 conflict since it
literally is a conflict but some just prefer to stick to a generic
500.

422 is the recommended behavior from respond_with and friends:

https://github.com/rails/rails/blob/master/actionpack/lib/action_controller/metal/responder.rb#L259

409 seems odd, given that the error could be "file too large" which isn't really "a conflict with the current state of the resource" as described in the RFC.

Also note that returning a 422 causes ActiveResource to behave in an expected manner (failing a save rather than raising an exception), which may-or-may-not be relevant for this use case.

--Matt Jones
 

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/caglVv5ftUsJ.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate