Exception: PerfectReach::ApiError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/perfect_reach/api_error.rb

Instance Method Summary collapse

Constructor Details

#initialize(code, res, request, request_path, params) ⇒ ApiError

Returns a new instance of ApiError.



6
7
8
9
10
11
12
13
14
# File 'lib/perfect_reach/api_error.rb', line 6

def initialize(code, res, request, request_path, params)
  # code is ugly, output is pretty
  error_text = res['errors'].present? ? [(res['errors'] || [])].flatten.map {|param, text| [param, text].map(&:to_s).reject(&:blank?).join(': ')}.join("\n") : res.inspect

  super("error #{code} while sending #{request.inspect} to #{request_path} with #{params.inspect}\n\n" +
        error_text +
        "\n\nPlease see http://api.perfect-reach.com for more informations on error numbers.\n\n"
  )
end