function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Daniel BallingerDaniel Ballinger 

Accessing the entire fault response from a CalloutException

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?

Daniel BallingerDaniel Ballinger
On IdeaExchange there is SOAPFault Information for Apex which would be worth promoting.
Deep SinghalDeep Singhal
Hi Daniel,
Is there any workaround for this. This is causing serious issue in identification of actual error message..