class Apruve::Error

Custom error class for rescuing from all API response-related Apruve errors

Attributes

response[R]

Public Class Methods

new(response=nil) click to toggle source

@param [Hash] response the decoded json response body

Calls superclass method
# File lib/apruve/error.rb, line 8
def initialize(response=nil)
  @response = response
  unless response.nil?
    super error_message
    # super 'Error!'
  end
end

Public Instance Methods

body() click to toggle source

@return [Hash]

# File lib/apruve/error.rb, line 17
def body
  @body ||= begin
    return {} unless response[:body]
    Utils.indifferent_read_access(response[:body])
  end
end
error_message() click to toggle source
# File lib/apruve/error.rb, line 24
def error_message
  # set_attrs
  errors = body.fetch('errors', nil)
  unless errors.nil?
    error = errors[0]
    extra = error[:source] ? " -- #{error[:source][:parameter]}" : ""
    extra += error[:detail] ? " -- #{error[:detail]}" : ""
    "#{self.class.name}(#{response[:status]}):: "\
    "#{response[:method].to_s.upcase} #{response[:url].to_s}: "\
    "#{error[:title]} #{extra}"
  end
end