Module: Scorpio::Ur

Defined in:
lib/scorpio/ur.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#scorpio_requestObject

Returns the value of attribute scorpio_request.



14
15
16
# File 'lib/scorpio/ur.rb', line 14

def scorpio_request
  @scorpio_request
end

Instance Method Details

#raise_on_http_errorvoid

This method returns an undefined value.

raises a subclass of Scorpio::HTTPError if the response has an error status. raises nothing if the status is 2xx. raises ClientError or one of its response-specific subclasses if the status is 4xx. raises ServerError or one of its response-specific subclasses if the status is 5xx. raises a generic HTTPError otherwise.

Raises:



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/scorpio/ur.rb', line 24

def raise_on_http_error
  error_class = Scorpio.error_classes_by_status[response.status]
  error_class ||= if (400..499).include?(response.status)
    ClientError
  elsif (500..599).include?(response.status)
    ServerError
  elsif !response.success?
    HTTPError
  end
  if error_class
    message = "Error calling operation #{scorpio_request.operation.human_id}:\n" + response.body
    raise(error_class.new(message).tap do |e|
      e.ur = self
      e.response_object = response.body_object
    end)
  end
  nil
end