Exception exception = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Exception.class);
if (exception instanceof GatewayException) {
GatewayException gatewayException = (GatewayException) exception;
if (gatewayException.getCode() == GatewayExceptionCode.AUTHORIZATION) {
String body = "Issue: " + gatewayException.getMessage();
createHttpErrorResponse(exchange, 401, body);
isNoteSpecialized = false;
} else if(gatewayException.getCode() == GatewayExceptionCode.AUTHORIZATION_BASIC) {
exchange.getOut().setHeader("WWW-Authenticate", "Basic realm=\"Secure Service\"");
String body = "Issue: " + gatewayException.getMessage();
createHttpErrorResponse(exchange, 401, body);
isNoteSpecialized = false;
} else if(gatewayException.getCode() == GatewayExceptionCode.API_NOT_ACTIVATED) {
String body = "Issue: " + gatewayException.getMessage();
createHttpErrorResponse(exchange, 403, body);
isNoteSpecialized = false;
} else if(gatewayException.getCode() == GatewayExceptionCode.VALIDATION) {
String body = "Issue: " + gatewayException.getMessage();
createHttpErrorResponse(exchange, 400, body);
isNoteSpecialized = false;
}
if (gatewayException.getCode() == GatewayExceptionCode.RATEORQUOTA) {
String body = "Issue: " + gatewayException.getMessage();
// Based on draft "Additional HTTP Status Codes; draft-nottingham-http-new-status-02"
// http://tools.ietf.org/html/draft-nottingham-http-new-status-02#page-4
createHttpErrorResponse(exchange, 429, "Too Many Requests", body);
isNoteSpecialized = false;
}
if (gatewayException.getCode() == GatewayExceptionCode.HTTP_METHOD) {
String body = "Issue: " + gatewayException.getMessage();
createHttpErrorResponse(exchange, 405, body);
isNoteSpecialized = false;
}
}