Class: Scorpio::Ur

Inherits:
Ur
  • Object
show all
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.



3
4
5
# File 'lib/scorpio/ur.rb', line 3

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:



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/scorpio/ur.rb', line 13

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