Sha256: 268f28818592fce24d226db26502dff02ed3c1df7e264c40f638d9e539b6dcc7

Contents?: true

Size: 900 Bytes

Versions: 4

Compression:

Stored size: 900 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(response.to_s, 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

4 entries across 4 versions & 1 rubygems

Version Path
fanforce-api-1.0.3 lib/fanforce/api/errors/server.rb
fanforce-api-1.0.2 lib/fanforce/api/errors/server.rb
fanforce-api-1.0.1 lib/fanforce/api/errors/server.rb
fanforce-api-1.0.0 lib/fanforce/api/errors/server.rb