Exception: Omie::RequestError

Inherits:
Error
  • Object
show all
Defined in:
lib/omie/error.rb

Overview

This exception must be used for failed requests with JSON responses from Omie.

Omie does not use the semantic value of HTTP status codes. It always returns the 500 error code to any failed request that has an associated message to the client, which was supposed to use the 400* error codes. Moreover, the error message is provided through a returned JSON object that has the keys ‘faultstring’ and ‘faultcode’. Such data is used in the exception message for a better understanding of the error.

Instance Attribute Summary

Attributes inherited from Error

#response

Instance Method Summary collapse

Methods inherited from Error

#initialize

Constructor Details

This class inherits a constructor from Omie::Error

Instance Method Details

#after_initializeObject

Sets fault_string and fault_code based on Omie’s responses for failed requests.



35
36
37
38
39
40
41
# File 'lib/omie/error.rb', line 35

def after_initialize
  return unless @response

  json = JSON.parse(@response.body)
  @fault_string = json['faultstring']
  @fault_code = json['faultcode']
end

#default_messageObject



49
50
51
# File 'lib/omie/error.rb', line 49

def default_message
  "Omie returned the error #{@fault_code}: '#{@fault_string}'"
end

#messageObject

Return the custom message or a default message with the fault code and string.



45
46
47
# File 'lib/omie/error.rb', line 45

def message
  @message || default_message
end