class Omie::RequestError

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.

Public Instance Methods

after_initialize() click to toggle source

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

# 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_message() click to toggle source
# File lib/omie/error.rb, line 49
def default_message
  "Omie returned the error #{@fault_code}: '#{@fault_string}'"
end
message() click to toggle source

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

# File lib/omie/error.rb, line 45
def message
  @message || default_message
end