Exception: FundAmerica::Error

Inherits:
StandardError
  • Object
show all
Defined in:
lib/fund_america/error.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parsed_response, code) ⇒ Error

Contructor method to take response code and parsed_response and give object methods in rescue - e.message and e.parsed_response



7
8
9
10
# File 'lib/fund_america/error.rb', line 7

def initialize(parsed_response, code)
  super(FundAmerica::Error.error_message(code, parsed_response))
  @parsed_response = parsed_response
end

Instance Attribute Details

#parsed_responseObject (readonly)

Returns the value of attribute parsed_response.



3
4
5
# File 'lib/fund_america/error.rb', line 3

def parsed_response
  @parsed_response
end

Class Method Details

.error_message(code, parsed_response) ⇒ Object

Method to return error message based on the response code



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/fund_america/error.rb', line 13

def self.error_message(code, parsed_response)
  case code
  when 401 then
    'Authentication error. Your API key is incorrect'
  when 403 then
    "Not authorized. You don't have permission to take action on a particular resource. It may not be owned by your account or it may be in a state where you action cannot be taken (such as attempting to cancel an invested investment)"
  when 404 then
    'Resource was not found'
  when 422 then
    "This usually means you are missing or have supplied invalid parameters for a request: #{parsed_response}"
  when 500 then
    "Internal server error. Something went wrong. This is a bug. Please report it to support immediately"
  else
    'An error occured. Please check parsed_response for details'
  end
end