class TicketingHub::Error

Attributes

response[RW]

Public Class Methods

new(response=nil) click to toggle source
# File lib/ticketing_hub/error.rb, line 5
def initialize response=nil
  @response = response
end

Public Instance Methods

response_body() click to toggle source
# File lib/ticketing_hub/error.rb, line 9
def response_body
  @response[:body]
end

Private Instance Methods

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

  message = if response_body
    ": #{response_body[:error] || response_body[:error_message] || ''}"
  else
    ''
  end
  errors = unless message.empty?
    response_body[:errors] ?  ": #{response_body[:errors].map{|e|e[:error_message]}.join(', ')}" : ''
  end
  "#{@response[:method].to_s.upcase} #{@response[:url].to_s}: #{@response[:status]}#{message}#{errors}"
end