class Invoicexpress::Error

Custom error class for rescuing from all Invoicexpress errors

Attributes

messages[RW]

Public Class Methods

new(response=nil) click to toggle source
Calls superclass method
# File lib/invoicexpress/error.rb, line 18
def initialize(response=nil)
  @response = response
  @messages = []

  super(build_error_message)
end

Public Instance Methods

response_body() click to toggle source
# File lib/invoicexpress/error.rb, line 25
def response_body
  @response_body ||=
    if (body = @response[:body]) && !body.empty?
      if body.is_a?(String) and body.start_with?("<")
        Invoicexpress::Models::Errors.parse(body)
      else
        body
      end
    else
      nil
    end
end

Private Instance Methods

build_error_message() click to toggle source
# File lib/invoicexpress/error.rb, line 40
def build_error_message
  return nil if @response.nil?

  message = if response_body
    if response_body.respond_to?(:errors)
      ": " + response_body.errors.join(", ")
    else
      ": " + response_body
    end
  else
    ''
  end

  "#{@response[:method].to_s.upcase} #{@response[:url].to_s}: #{@response[:status]}#{message}"
end