Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

ActiveResource and 422 Status Code and Response Message

#6471

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

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

State: new
Milestone: none
Assigned to: nobody
Importance: none

Activity

  1. Markus Schwed
    Markus Schwed
    • Tag set to activeresource, statuscodes

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

    March 3rd, 2011 @ 08:03 AM