class XeroRuby::ApiError

Attributes

code[R]
response_body[R]
response_headers[R]

Public Class Methods

new(arg = nil) click to toggle source

Usage examples:

ApiError.new
ApiError.new("message")
ApiError.new(:code => 500, :response_headers => {}, :response_body => "")
ApiError.new(:code => 404, :message => "Not Found")
Calls superclass method
# File lib/xero-ruby/api_error.rb, line 21
def initialize(arg = nil)
  if arg.is_a? Hash
    if arg.key?(:message) || arg.key?('message') || arg.key?(:Message) || arg.key?('Message')
      super(arg[:message] || arg['message'] || arg.key?(:Message) || arg.key?('Message'))
    else
      super arg
    end

    arg.each do |k, v|
      instance_variable_set "@#{k}", v
    end
  else
    @message = arg
    super arg
  end
end

Public Instance Methods

message() click to toggle source
# File lib/xero-ruby/api_error.rb, line 43
def message
  if @message.nil?
    msg = "Error message: the server returns an error"
  else
    msg = @message
  end

  msg += "\nHTTP status code: #{code}" if code
  msg += "\nResponse headers: #{response_headers}" if response_headers
  msg += "\nResponse body: #{response_body}" if response_body

  msg
end
to_s() click to toggle source

Override to_s to display a friendly error message

# File lib/xero-ruby/api_error.rb, line 39
def to_s
  message
end