myfreecomm/passaporteweb-client-ruby

View on GitHub
lib/passaporte_web/client/exception.rb

Summary

Maintainability
A
0 mins
Test Coverage
# Exception class raised whenever the underlying client receives an error response.
#
# [API]
#   Documentation:
#
class PassaporteWeb::Client::Exception < StandardError
  # Creates an instance of this exception.
  #
  # @param [String] message The exception message.
  # @param [#status, #headers, #body] response The client's HTTP response object.
  def initialize(message, response)
    super(message)
    @response = response
  end

  # @return [Integer] HTTP response's status.
  def status
    @response.status if @response
  end

  # @return [Integer] HTTP response's headers.
  def headers
    @response.headers if @response
  end

  # @return [Integer] HTTP response's body.
  def body
    @response ? @response.body : ''
  end
end