Exception: Shippinglogic::UPS::Error

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

Overview

If UPS responds with an error, we try our best to pull the pertinent information out of that response and raise it with this object. Any time UPS says there is a problem an object of this class will be raised.

Tip

If you want to see the raw request / respose catch the error object and call the request / response method. Ex:

begin
  # my UPS code
rescue Shippinglogic::UPS::Error => e
  # do whatever you want here, just do:
  # e.request
  # e.response
  # to get the raw response from UPS
end

Instance Attribute Summary

Attributes inherited from Error

#errors, #request, #response

Instance Method Summary collapse

Methods inherited from Error

#add_error, #message

Constructor Details

#initialize(request, response) ⇒ Error

Returns a new instance of Error.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/shippinglogic/ups/error.rb', line 20

def initialize(request, response)
  super
  
  if response.blank?
    add_error("The response from UPS was blank.")
  elsif !response.is_a?(Hash)
    add_error("The response from UPS was malformed and was not in a valid XML format.")
  elsif errors = response.fetch(:response, {})[:error]
    errors = errors.is_a?(Array) ? errors : [errors]
    errors.delete_if { |error| Response::SUCCESSFUL_SEVERITIES.include?(error[:error_severity]) }
    errors.each { |error| add_error(error[:error_description], error[:error_code]) }
  else
    add_error(
      "There was a problem with your UPS request, and we couldn't locate a specific error message. This means your response " +
      "was in an unexpected format. You might try glancing at the raw response by using the 'response' method on this error object."
    )
  end
  
  super(errors.collect { |error| error[:message] }.join(", "))
end