views:

284

answers:

1

I asked something similar to this before and never got an answer, here's a shortened version

I have a User activeresource model. I make a simple call on my client to the service

response = User.find(id).put(:activate, :activation_code => activation_code)

If there were errors on the service (ie. activation_code didn't match) I return

render :xml => @user.errors, :status => :unprocessable_entity

So apparently any error response with activeresource must be handled by a resue

rescue ActiveResource::ResourceInvalid

That's all fine and dandy, except that the response in the initial call does not get set. I have no body from that response at all, so @user.errors is never returned. What do I need to get the proper object back? besides returning 200. Any 'success' response code populates the response variable fine. But always returning 200 seems like a mistake.

+1  A: 

So I was a bit mistaken there, in the rescue block

rescue ActiveResource::ResourceInvalid => e

e gets populated. The service returns

render :xml => @user.errors, :unprocessable_entity

So e.response.body contains the errors xml. I then on my client side just say

user.errors.from_xml(e.response.body)

and the user is now populated with the proper errors.

brad