Sha256: cfe04bff3d91e70452f8f9a7cf38fcdb958c43a4ee2c439af1d3f5a28fff2d69

Contents?: true

Size: 907 Bytes

Versions: 12

Compression:

Stored size: 907 Bytes

Contents

class Fanforce::API::Error::Server < Fanforce::API::Error

  def initialize(response, request, requested_url, requested_params)
    @response_body = response.to_s

    if Fanforce.is_present?(response.body)
      begin
        @response_hash = MultiJson.load(response, symbolize_keys: true)
        @errors = @response_hash[:errors]
      rescue Exception => e
        raise Fanforce::API::Error::Decoding.new(e, response, request, requested_url, requested_params)
      end
    else
      @errors = [{message: "(Response body from #{response.code} error was empty: #{response.body})"}]
    end

    super(@errors[0][:message], response, request, requested_url, requested_params)
  end

  def to_hash
    @response_hash
  end

  def curl_command
    method = begin @request.method rescue nil end
    Fanforce.curl_command(method, @requested_url, @requested_params)
  end

  def code; @response.code end

end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
fanforce-api-2.0.0.rc6 lib/fanforce/api/errors/server.rb
fanforce-api-2.0.0.rc5 lib/fanforce/api/errors/server.rb
fanforce-api-2.0.0.rc4 lib/fanforce/api/errors/server.rb
fanforce-api-2.0.0.rc3 lib/fanforce/api/errors/server.rb
fanforce-api-2.0.0.rc2 lib/fanforce/api/errors/server.rb
fanforce-api-2.0.0.rc1 lib/fanforce/api/errors/server.rb
fanforce-api-1.6.0 lib/fanforce/api/errors/server.rb
fanforce-api-1.6.0.rc3 lib/fanforce/api/errors/server.rb
fanforce-api-1.6.0.rc2 lib/fanforce/api/errors/server.rb
fanforce-api-1.6.0.rc1 lib/fanforce/api/errors/server.rb
fanforce-api-1.0.5 lib/fanforce/api/errors/server.rb
fanforce-api-1.0.4 lib/fanforce/api/errors/server.rb