Sha256: 4561b27a2c47e441aa966790f05f01c18ac29f9bb83fc044b3cae7d6992a6ad2
Contents?: true
Size: 1.67 KB
Versions: 1
Compression:
Stored size: 1.67 KB
Contents
module Shippinglogic class UPS # 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 class Error < Shippinglogic::Error 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 end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
shippinglogic-1.2.3 | lib/shippinglogic/ups/error.rb |