This project is archived and is in readonly mode.

#6471 new
Chad W. Taylor

ActiveResource and 422 Status Code and Response Message

Reported by Chad W. Taylor | February 25th, 2011 @ 08:13 PM

The 422 unprocessable_entity appears to be limited to the "save" operations. It would be nice that it is not limited to saves. It would be nice to use status codes, other than 200, to display errors from the body so we know what was wrong with our get request.

For instance, if I did this:

[code] person = Person.find(:all, :params => {:first_name => "John"})
[/code]

The API server may require a combination of both :first_name and :last_name to work so the error message would show that the last name is a required field before the find operation can be processed hence the unprocessable_entity used. It is able to raise 422 however the response body is not being picked up other than the save operations.

It would be nice if the following code (activeresource/lib/active_resource/custom_methods.rb) in ActiveResource project shows:

[code] def put(method_name, options = {}, body = '')
begin

connection.put(custom_method_element_url(method_name, options), body, self.class.headers)

rescue ResourceInvalid => error

errors.from_xml(error.response.body) # need to also handle JSON requests as well

end self end
[/code]

Hope that can be considered!

Thanks much,
Chad

Comments and changes to this ticket

  • Markus Schwed

    Markus Schwed March 3rd, 2011 @ 08:03 AM

    • Tag set to activeresource, statuscodes

    I think, that would be a nice feature/fix could you do this and add a patch?

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

People watching this ticket

Pages