java-camel-server.errorProcessor.mustache Maven / Gradle / Ivy
/**
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) ({{{generatorVersion}}}).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
package {{basePackage}};
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.component.bean.validator.BeanValidationException;
import org.springframework.stereotype.Component;
{{#jackson}}
import com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException;{{/jackson}}
@Component("{{camelValidationErrorProcessor}}")
public class ValidationErrorProcessor implements Processor {
@Override
public void process(Exchange exchange) throws Exception {
Exception fault = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Exception.class);
int httpStatusCode = 500;
if (fault instanceof BeanValidationException) {
httpStatusCode = 400;
}
{{#jackson}}
if (fault instanceof UnrecognizedPropertyException) {
httpStatusCode = 400;
}
{{/jackson}}
exchange.getIn().setHeader(Exchange.HTTP_RESPONSE_CODE, httpStatusCode);
exchange.getIn().setBody(fault.getMessage());
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy