title: spring integration error handling different types
body: <p>I am using spring integration XML and want to know what is the best way to deal with error handling.</p>
  
  <p>I am connecting to s3 using <code>s3-inbound-streaming-channel-adapter</code> and then transforming the csv file from s3 bucket.</p>
  
  <p>Potential errors that can happen are:</p>
  
  <ol>
  <li>Transformation Exception could happen if a line in the file is not valid and so can throw a custom error:</li>
  </ol>
  
  <p><code>LineTransformationException</code></p>
  
  <ol start="2">
  <li><p>What if on s3 bucket an image file is placed by mistake and again could get Transformation Exception</p></li>
  <li><p>s3 could be down and could get</p></li>
  </ol>
  
  <p>Caused by: com.amazonaws.SdkClientException: Unable to execute HTTP request: Connect to localhost:4572 [localhost/127.0.0.1] failed:  Connection refused</p>
  
  <p>And the list of many known and unknown errors can go on...</p>
  
  <ol>
  <li><p>So what is the <strong>best</strong> way to handle all these errors? Through custom <code>ErrorHandler</code> or <code>exception-type-router</code></p></li>
  <li><p>If doing it through <code>ErrorHandler</code> then how to cater for so many Exceptions.</p></li>
  <li><p>And is there a catch-all exception handler?</p>
  
  <p>public class ErrorHandler {</p>
  
  <p>public void handleFailure(Message errorMmessage) {</p>
  
  <pre><code>MessagingException payload = (MessagingException) errorMmessage.getPayload();
  
  LOG.info("&gt;&gt;--- Exception --- " + payload.getCause());
  </code></pre>
  
  <p>}}</p></li>
  </ol>
  
  <p>or </p>
  
  <pre><code> &lt;int:exception-type-router input-channel="errorChannel"
                             default-output-channel="nullChannel"&gt;
  
      &lt;int:mapping exception-type="com.api.exception.TransformationException"
                   channel="transformErrorChannel"/&gt;
  
      &lt;int:mapping exception-type="com.amazonaws.SdkClientException"
                   channel="clientErrorChannel"/&gt;
  
  &lt;/int:exception-type-router&gt;
  
  &lt;int:channel id="transformErrorChannel"/&gt;
  
  &lt;int:service-activator ref="errorHandler"
                         method="handleFailure"
                         input-channel="transformErrorChannel"
                         output-channel="nullChannel"/&gt;
  
  &lt;int:service-activator ref="clientErrorHandler"
                         method="handleFailure"
                         input-channel="clientErrorChannel"
                         output-channel="nullChannel"/&gt;
  </code></pre>