Skip to content

How to handle 4xx(without retry) and 5xx (with retry) exceptions in camel

I’ve a camel route which makes API request, the external service may though 4xx or 5xx. I have written HttpOperationFailedException handler to handle all HTTP related exception and I’m retrying all the Http exceptions irrespective of whether its client side or server side exceptions. I would like to handle them in a way, I need to avoid the reties for client side exceptions.

Here is my route and exception code, looks like. Can anyone suggest best way to handle these scenarios ?

        .log("${exception} Http Communication Exception while making API request")

        .process(exchange -> exchange.getIn().setBody(
            new RequestBody(
        .setHeader(Exchange.HTTP_METHOD, constant("POST"))


You could try something along the lines of:

                    .when(simple("${exception.getStatusCode()} == '400'"))
                    .when(simple("${exception.getStatusCode()} == '500'"))