class Bfwd::ApiError

Attributes

code[R]
parsed[R]
response_body[R]
response_headers[R]

Public Class Methods

new(arg = nil) click to toggle source

Usage examples:

ApiError.new
ApiError.new("message")
ApiError.new(:code => 500, :response_headers => {}, :response_body => "")
ApiError.new(:code => 404, :message => "Not Found")
Calls superclass method
# File lib/bf_ruby2/api_error.rb, line 24
def initialize(arg = nil)
  if arg.is_a? Hash
    if arg.key?(:message) || arg.key?('message')
      super(arg[:message] || arg['message'])
    else
      super arg
    end

    arg.each do |k, v|
      instance_variable_set "@#{k}", v
    end

    parsed = JSON.parse(arg[:response_body]) rescue {'errorMessage': arg.response_body}
  else
    super arg
    parsed = {'errorMessage': 'Failed to parse error response from API; was not JSON-formatted.'}
  end
  @parsed = parsed
end