I was trying work out a way of getting customizable errors from the SwaggerRouter when something fails. Right now it seems that it is only possible to get 400 Bad Request from any Runtime Exception, and any error on the handling of the request is automatically managed as well, from com.github.phiz71.vertx.swagger.router.SwaggerRouter
:
private static void configureRoute(Route route, String serviceId, Operation operation, EventBus eventBus, Function<RoutingContext, DeliveryOptions> configureMessage) {
...
route.handler(context -> {
try {
JsonObject message = new JsonObject();
operation.getParameters().forEach(parameter -> {
String name = parameter.getName();
Object value = PARAMETER_EXTRACTORS.get(parameter.getIn()).extract(name, parameter, context);
message.put(name, value);
});
// callback to configure message e.g. provide message header values
DeliveryOptions deliveryOptions = configureMessage != null ? configureMessage.apply(context) : new DeliveryOptions();
eventBus.<String> send(serviceId, message, deliveryOptions, operationResponse -> {
if (operationResponse.succeeded()) {
if (operationResponse.result().body() != null) {
vertxLogger.debug(operationResponse.result().body());
manageHeaders(context.response(), operationResponse.result().headers());
context.response().end(operationResponse.result().body());
} else {
context.response().end();
}
} else {
vertxLogger.debug("Internal Server Error", operationResponse.cause());
manageError((ReplyException)operationResponse.cause(), context.response());
}
});
} catch (RuntimeException e) {
vertxLogger.debug("sending Bad Request", e);
badRequestEnd(context.response());
}
});