vendor/bundle/ruby/2.3.0/gems/freelancer-0.1.1/lib/freelancer/client.rb
# Raise an error for the specified API method response if any
Raise an error for the specified API method response if any
Raise an error for the specified API method response if any
def raise_api_errors!(response)
      case response.code.to_i
      when 1..199
        raise FreelancerRequestError.new("Got response code #{response.code} when executing API request")
      when 201..503
        raise FreelancerRequestError.new("Got response code #{response.code} when executing API request")
      end
      json = JSONMapper::Parser.parse(response.body)
      raise FreelancerResponseError.new("No or invalid response received when executing API request") if json.nil?
      if json.keys.size == 1 && json.keys.first == :errors
        error_code = json[:errors][:error][:code]
        error_message = json[:errors][:error][:msg]
        error_description = json[:errors][:error][:longmsg]
        raise FreelancerResponseError.new("#{error_message} - #{error_description} (code #{error_code})")
      end
    end
def raise_api_errors! ( response ) case response . code . to_i when 1 .. 199 raise FreelancerRequestError . new ( "Got response code #{response.code} when executing API request" ) when 201 .. 503 raise FreelancerRequestError . new ( "Got response code #{response.code} when executing API request" ) end json = JSONMapper :: Parser . parse ( response . body ) raise FreelancerResponseError . new ( "No or invalid response received when executing API request" ) if json . nil? if json . keys . size == 1 && json . keys . first == :errors error_code = json [ :errors ] [ :error ] [ :code ] error_message = json [ :errors ] [ :error ] [ :msg ] error_description = json [ :errors ] [ :error ] [ :longmsg ] raise FreelancerResponseError . new ( "#{error_message} - #{error_description} (code #{error_code})" ) end end
Raise an error for the specified API method response if any
Raise an error for the specified API method response if any
# Attempt to convert the response to a JSON data structure # If we didn't get a proper response, raise an error # If the JSON data has an error element as the only element, # assume this request fails
response
<not_specific>