• Deep Singhal
  • NEWBIE
  • 0 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies

I'm calling a web service that will return a Fault and FaultMessage(s) if there is an issue with the request. E.g.

 

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Body>
    <s:Fault>
      <faultcode>s:Client</faultcode>
      <faultstring xml:lang="en-US">The creator of this fault did not specify a Reason.</faultstring>
      <detail>
        <DataAccessFault xmlns="http://www.example.com/api" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
          <FaultMessges xmlns:a="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
            <a:string>Validation Error(s) occurred during Save.</a:string>
            <a:string>Meaningful error message appears here</a:string>
          </FaultMessges>
          <FaultObjectType>Order</FaultObjectType>
          <FaultOperationType>Insert</FaultOperationType>
        </DataAccessFault>
      </detail>
    </s:Fault>
  </s:Body>
</s:Envelope>

 When this gets handled by Apex it gets turned into a CalloutException:

 

System.CalloutException 
  Cause: null 
  Message: Web service callout failed: WebService returned a SOAP Fault: The creator of this fault did not specify a Reason. faultcode=s:Client faultactor= 

 The issue I have is that the getMessage() method doesn't return the entire SOAP reponse. It has been truncated before the useful information appears.

 

Is there some way to recover the entire response from the CalloutException in code so I can give a meaning error back to the user?

 

Currently I need to resort to capturing the Outbound SOAP message and response using the third party tool like soapUI. While this works for debugging, it doesn't help the users during normal usage.

 

Related: This post from 2009 seems to be dealing with the same issue but has not resolution - CalloutException: Problem with contents of fault detail?