module AfterShip::ErrorHandler

Response handling logic.

Constants

CODE_TO_ERROR_MAP

Map meta codes to error classes.

SUCCESS_CODES

These mean that the response is good.

Public Instance Methods

check(meta) click to toggle source

Check the meta code of the response. If it isn't 200 or 201, raise an error.

@param meta [Hash] @option meta :code [Fixnum] @option meta :message [String, nil] @option meta :type [String, nil]

# File lib/after_ship/core/error_handler.rb, line 53
def check(meta)
  code = meta.fetch(:code)

  return if SUCCESS_CODES.include?(code)

  error_class = error_class_for(code)
  fail error_class, meta[:message]
end
error_class_for(code) click to toggle source

Pick the corresponding error class for the code.

# File lib/after_ship/core/error_handler.rb, line 63
def error_class_for(code)
  CODE_TO_ERROR_MAP[code] || Error::UnknownError
end
precheck(response) click to toggle source

Did it timeout? If the body empty?

@param response [Typhoeus::Response]

# File lib/after_ship/core/error_handler.rb, line 41
def precheck(response)
  fail Error::Timeout, "#{response.effective_url} cannot be reached" if
    response.timed_out?
end