Error Handling

Error handling for non-SOAP operations is different from error handling for SOAP operations. The SOAP specification provides an error handling mechanism that is not present for non-SOAP operations. For a SOAP operation, a fault is returned as a SOAP exception. For a non-SOAP request, the contents of the SOAP fault are returned as an XML document. These SOAP fault documents are returned in situations such as schema validation failures or when operation types are unrecognized. In the following example, a SOAP fault document is returned from a schema validation failure in which the “AccountNumber” element was incorrectly sent as the “AccountNumberx” element:

<soapenv:Fault xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<faultcode>soapenv:Server</faultcode>
<faultstring>5: Schema validation failed for request.</faultstring>
<detail>
<con:fault xmlns:con="http://www.bea.com/wli/sb/context">
     <con:errorCode>5</con:errorCode>
     <con:reason>Schema validation failed for request.</con:reason>
     <con:details>
         <con1:ValidationFailureDetail xmlns:con1="http://www.bea.com/wli/sb/stages/transform/config">
             <con1:message>Expected element 'AccountNumber@http://fedex.com/ws/ship/v8' instead of 'AccountNumberx@http://fedex.com/ws/ship/v8' here in element ClientDetail@http://fedex.com/ws/ship/v8</con1:message>
             <con1:xmlLocation>
                 <ship:AccountNumberx xmlns:ship="http://fedex.com/ws/ship/v8">000000000</ship:AccountNumberx>
             </con1:xmlLocation>
             <con1:message>Expected element 'AccountNumber@http://fedex.com/ws/ship/v1' before the end of the content in element ClientDetail@http://fedex.com/ws/ship/v8</con1:message>
             <con1:xmlLocation>
                 <ship:ClientDetail xmlns:ship="http://fedex.com/ws/ship/8">
                     <ship:AccountNumberx>000000000000000000</ship:AccountNumberx>
                     <ship:MeterNumber>0000000</ship:MeterNumber>
                 </ship:ClientDetail>
             </con1:xmlLocation>
         </con1:ValidationFailureDetail>
     </con:details>
     <con:location>
         <con:node>Validate</con:node>
         <con:pipeline>Validate_request</con:pipeline>
         <con:stage>ValidateRequest</con:stage>
         <con:path>request-pipeline</con:path>
     </con:location>
</con:fault>
</detail>
</soapenv:Fault>

Each reply should be checked for the Fault element to indicate failure in processing the message. Note that the normal error processing still applies; this is an additional error check for incorrect syntax in XML documents.

Keep in mind that if you use either the SOAP or non-SOAP version of FedEx Web Services, labels are returned as Base64 encoded. To print shipping labels, you must decode labels before sending them to your printer. For more information on Base64 decoding, see Creating a Label.