title: How to do custom error handling in an apache camel rest api?
body: <p>I have an apache camel rest api which downloads a file from S3. I send json input<code>(key, bucketname, accessKey, secretKey, region)</code> in order to write the URI. The code looks like this:</p>
  <pre><code>public static class HelloRoute extends RouteBuilder {
         
     @Override
     public void configure() {
       rest(&quot;/&quot;)
       .post(&quot;file-from-s3&quot;)
       .route()
       .setHeader(AWS2S3Constants.KEY, key)
       .to(&quot;aws2-s3://bucketname?accessKey=INSERT&amp;secretKey=INSERT&amp;region=INSERT&amp;operation=getObject&quot;)
        .endRest();
            }
  }
  
  </code></pre>
  <p>I am able to get the respective json input in the places mentioned in the above code by using a <code>JSONObject</code> as the body.</p>
  <p>If suppose, I enter a wrong value in my json input(for ex accessKey), I get an error like</p>
  <pre><code>The AWS Access Key Id you provided does not exist in our records. (Service: S3, Status Code: 403, Request ID: 6923BEC55C1FD5F1, Extended Request ID: re5Rb7I76j9jvGqhSQXgjUoMwOZqsprg22bOGD+BDbuj0zrRrf0FceLaapvpR4KcNDY6GntNiF0=)
  </code></pre>
  <p>which is not very user friendly. How can I write a custom error handler for this which will just return an error message for the above case like <code> Wrong Access Key</code></p>