class EasyMeli::ErrorParser

Constants

ERROR_LIST
STATUS_ERRORS

Public Class Methods

error_class(response) click to toggle source
# File lib/easy_meli/error_parser.rb, line 20
def self.error_class(response)
  ERROR_LIST.find { |key, _| self.error_message_from_body(response)&.include?(key) }&.last
end
status_error_class(response) click to toggle source
# File lib/easy_meli/error_parser.rb, line 24
def self.status_error_class(response)
  return unless self.status_code_listed?(response) || self.server_side_error?(response)

  STATUS_ERRORS[response.code] || EasyMeli::ServerError
end

Private Class Methods

error_message_from_body(response) click to toggle source
# File lib/easy_meli/error_parser.rb, line 32
def self.error_message_from_body(response)
  response['message'].to_s.empty? ? response['error'] : response['message']
end
server_side_error?(response) click to toggle source
# File lib/easy_meli/error_parser.rb, line 36
def self.server_side_error?(response)
  response.code >= 500
end
status_code_listed?(response) click to toggle source
# File lib/easy_meli/error_parser.rb, line 40
def self.status_code_listed?(response)
  STATUS_ERRORS.keys.include?(response.code)
end