Sha256: 860250f24a9c9da84598a65f469af418ef546b6c890a125757d546ab92dfc626

Contents?: true

Size: 1.47 KB

Versions: 6

Compression:

Stored size: 1.47 KB

Contents

require_relative 'utils'

class Fanforce
  class 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_param(@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; end
  end

  class BadRequestError          < Error
    def code; @http_status = 400     end
  end

  class Unauthorized             < Error
    def code; @http_status = 401     end
  end

  class ForbiddenError           < Error
    def code; @http_status = 403     end
  end

  class NotFoundError            < Error
    def code; @http_status = 404     end
  end

  class UnprocessableEntityError < Error
    def code; @http_status = 422     end
  end

  class UnknownError             < Error
    def code; @http_status ||= 500; 500 end
    def initialize(response, request, path, query_params)
      @http_status = response.code
      super(response, request, path, query_params)
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
fanforce-0.5.2 lib/fanforce/errors.rb
fanforce-0.5.1 lib/fanforce/errors.rb
fanforce-0.5.0 lib/fanforce/errors.rb
fanforce-0.4.9 lib/fanforce/errors.rb
fanforce-0.4.8 lib/fanforce/errors.rb
fanforce-0.4.7 lib/fanforce/errors.rb