Sha256: ea00f0cd317ee68a30bcda5b30334cfd97317d40fdad5b40fb03da730b6549d0

Contents?: true

Size: 792 Bytes

Versions: 2

Compression:

Stored size: 792 Bytes

Contents

require_relative 'utils'

class Fanforce::Api::Error < StandardError
  attr_accessor :path, :query_params, :request, :response, :request_url, :http_status

  def initialize(response, request, path, query_params)
    @query_params = query_params
    @path = path
    @request = request
    begin
      @response = MultiJson.load(response, :symbolize_keys => true)
    rescue Exception => e
      @response = "Error decoding JSON in Fanforce gem: #{e.message}"
    end
    @request_url = "#{@path}?#{Fanforce::Utils.to_query_string(@query_params)}"
    super(@response.is_a?(Hash) ? @response[:msg] : @response)
  end

  def curl_command
    method = begin @request.method rescue nil end
    Fanforce::Utils.curl_command(method, @path, @query_params)
  end

  def code; @response.code end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
fanforce-0.6.1 lib/fanforce/api/error.rb
fanforce-0.6.0 lib/fanforce/api/error.rb