Exception: Shippinglogic::FedEx::Error
- Inherits:
-
StandardError
- Object
- StandardError
- Shippinglogic::FedEx::Error
- Defined in:
- lib/shippinglogic/fedex/error.rb
Overview
If FedEx 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 FedEx 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 fedex code
rescue Shippinglogic::FedEx::Error => e
# do whatever you want here, just do:
# e.request
# e.response
# to get the raw response from fedex
end
Instance Attribute Summary collapse
-
#errors ⇒ Object
Returns the value of attribute errors.
-
#request ⇒ Object
Returns the value of attribute request.
-
#response ⇒ Object
Returns the value of attribute response.
Instance Method Summary collapse
- #add_error(error, code = nil) ⇒ Object
-
#initialize(request, response) ⇒ Error
constructor
A new instance of Error.
Constructor Details
#initialize(request, response) ⇒ Error
Returns a new instance of Error.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/shippinglogic/fedex/error.rb', line 22 def initialize(request, response) self.request = request self.response = response if response.blank? add_error("The response from FedEx was blank.") elsif !response.is_a?(Hash) add_error("The response from FedEx was malformed and was not in a valid XML format.") elsif notifications = response[:notifications] notifications = notifications.is_a?(Array) ? notifications : [notifications] notifications.delete_if { |notification| Response::SUCCESSFUL_SEVERITIES.include?(notification[:severity]) } notifications.each { |notification| add_error(notification[:message], notification[:code]) } elsif response[:"soapenv:fault"] && detail = response[:"soapenv:fault"][:detail][:"con:fault"] add_error(detail[:"con:reason"], detail[:"con:error_code"]) if detail[:"con:details"] && detail[:"con:details"][:"con1:validation_failure_detail"] && = detail[:"con:details"][:"con1:validation_failure_detail"][:"con1:message"] = .is_a?(Array) ? : [] .each { || add_error() } end else add_error( "There was a problem with your fedex 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] }.to_sentence) end |
Instance Attribute Details
#errors ⇒ Object
Returns the value of attribute errors.
20 21 22 |
# File 'lib/shippinglogic/fedex/error.rb', line 20 def errors @errors end |
#request ⇒ Object
Returns the value of attribute request.
20 21 22 |
# File 'lib/shippinglogic/fedex/error.rb', line 20 def request @request end |
#response ⇒ Object
Returns the value of attribute response.
20 21 22 |
# File 'lib/shippinglogic/fedex/error.rb', line 20 def response @response end |
Instance Method Details
#add_error(error, code = nil) ⇒ Object
51 52 53 |
# File 'lib/shippinglogic/fedex/error.rb', line 51 def add_error(error, code = nil) errors << {:message => error, :code => code} end |