Sha256: 9969b617dafb5513210325c04c20b2d86c3961d7190ad77f155dbc0de2cc82eb
Contents?: true
Size: 1.76 KB
Versions: 11
Compression:
Stored size: 1.76 KB
Contents
require_relative 'utils' class Fanforce::Api::Error < StandardError attr_accessor :response, :request, :requested_url, :requested_params, :errors def initialize(message, response, request, requested_url, requested_params) @response = response @request = request @requested_url = requested_url @requested_params = requested_params @message = message super(message) end def curl_command method = begin @request.method rescue nil end Fanforce::Utils.curl_command(method, @requested_url, @requested_params) end def code; @response.respond_to?(:code) ? @response.code : 500 end def to_s; @message end def to_hash; {} end end class Fanforce::Api::ServerError < Fanforce::Api::Error def initialize(response, request, requested_url, requested_params) @response_body = response.to_s 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 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::Utils.curl_command(method, @requested_url, @requested_params) end def code; @response.code end end class Fanforce::Api::DecodingError < Fanforce::Api::Error def initialize(e, response, request, requested_url, requested_params) @message = "There was a Fanforce gem error while decoding JSON response: #{e.message}" @errors = [{message: @message}] super(@message, response, request, requested_url, requested_params) end def to_hash {errors: @errors} end def code; 500 end end
Version data entries
11 entries across 11 versions & 2 rubygems