Exception: Fanforce::API::ServerError

Inherits:
Error
  • Object
show all
Defined in:
lib/fanforce/api/error.rb

Instance Attribute Summary

Attributes inherited from Error

#errors, #request, #requested_params, #requested_url, #response

Instance Method Summary collapse

Methods inherited from Error

#to_s

Constructor Details

#initialize(response, request, requested_url, requested_params) ⇒ ServerError

Returns a new instance of ServerError.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/fanforce/api/error.rb', line 27

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

  if Fanforce::Utils.is_present?(response.body)
    begin
      @response_hash = Fanforce::Utils.decode_json(response)
      @errors = @response_hash[:errors]
    rescue Exception => e
      raise Fanforce::API::DecodingError.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

Instance Method Details

#codeObject



53
# File 'lib/fanforce/api/error.rb', line 53

def code; @response.code end

#curl_commandObject



48
49
50
51
# File 'lib/fanforce/api/error.rb', line 48

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

#to_hashObject



44
45
46
# File 'lib/fanforce/api/error.rb', line 44

def to_hash
  @response_hash
end