I find it inconsistent that a normal response and an exception response don't use the same method name to get the status code.
A normal response has a method called code for the status code, and an exception response got method named 'http_code`.
Maybe there is a reason for this, but I would like to see an alias named code for the http_code method in the ExceptionResponse, so it is less inconsistent.
begin
response = RestClient::Request.execute(method: :get, url: "https://www.google.com")
rescue
RestClient::ExceptionWithResponse => response
end
# response.code => 200
# response.http_code => NoMethodError (undefined method `http_code' for <RestClient::Response 200 "<!doctype h...">:RestClient::Response)
begin
response = RestClient::Request.execute(method: :get, url: "https://www.google.com/404")
rescue
RestClient::ExceptionWithResponse => response
end
# response.code => # NoMethodError (undefined method `code' for #<RestClient::NotFound: 404 Not Found>)
# response.http_code => 404