Exception: SlimpayClient::Error

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

Overview

To display SlimpayClient error messages with the HTTP code.

Possible API errors

  • code: 906 message: “Error : Could not find acceptable representation”

  • code: 906 message: “Error : Request method ‘POST’ not supported”

  • code: 906 message: “Error : Content type ‘application/x-www-form-urlencoded’ not supported”

  • code: 904 message: “Access denied : cannot access creditor democreditor”

  • error:“invalid_token”, error_description: “Invalid access token: 1234-123456-abcdef-123456”

  • code: 205, message: “Client data are inconsistent : missing query parameters creditorReference and/or rum”

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(http_response) ⇒ Error

Returns either formated error with its HTTP code or the raw HTTP response.

Arguments:
http_response: (HTTParty::Response)


21
22
23
24
25
26
27
28
# File 'lib/slimpay_client/error.rb', line 21

def initialize(http_response)
  if defined?(http_response.code)
    display_http_error(http_response)
  else
    @message = JSON.parse(http_response.body)
  end
  fail self, @message.to_s
end

Instance Attribute Details

#messageObject (readonly)

Returns the value of attribute message.



12
13
14
# File 'lib/slimpay_client/error.rb', line 12

def message
  @message
end

Class Method Details

.emptyObject

If the HTTP response is nil or empty returns an actual message.



14
15
16
# File 'lib/slimpay_client/error.rb', line 14

def self.empty
  @message = {code: 418, message: 'The answer was empty.'}
end

Instance Method Details

#to_sObject



30
31
32
# File 'lib/slimpay_client/error.rb', line 30

def to_s
  @message
end