module Scorpio::Ur

Attributes

scorpio_request[RW]

Public Instance Methods

raise_on_http_error() click to toggle source

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.

@raise [Scorpio::HTTPError] @return [void]

# 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