1

I want to know the status of my API call when its success.

begin
  @project = Project.find( id: '22', authorization: @auth )
rescue ActiveRestClient::HTTPClientException, ActiveRestClient::HTTPServerException => e
  Rails.logger.error("Project find returned #{e.status} #{e.message}")
end

When my API fails to get a project with an id '22', i get the status and the message as exception. But how can i get the status 200 when its a success call.

Taryn East
  • 27,486
  • 9
  • 86
  • 108
Mathew
  • 231
  • 1
  • 4
  • 14

1 Answers1

0

From memory, you can access the HTTP status of a response object using simply:

@project._status

https://github.com/whichdigital/active-rest-client/blob/master/lib/active_rest_client/base.rb#L10

I was the main author of this project, although I no longer work for Which so am not really responsible for its future direction. Feel free to ask any other questions.

Andy Jeffries
  • 392
  • 3
  • 15