package io.gatekeeper.api;

import io.gatekeeper.node.Node;
import io.gatekeeper.node.ServiceContainer;
import io.vertx.core.http.HttpServerRequest;
import io.vertx.ext.web.RoutingContext;
import org.apache.http.entity.ContentType;
import org.json.JSONObject;

public abstract class AbstractController {

    protected final ServiceContainer container;

    public AbstractController(ServiceContainer container) {
        assert null != container;

        this.container = container;
    }

    public void handle(RoutingContext context) {
        JSONObject data = handle(context.request());

        context.response().putHeader("content-type", ContentType.APPLICATION_JSON.toString());

        context.response().end(data.toString(4));
    }

    protected abstract JSONObject handle(HttpServerRequest request);
}

@@ -561,37 +561,518 @@
 data
- = handle(context.request());
+;%0A%0A        try %7B%0A            data = handle(context.request());%0A        %7D catch (Exception exception) %7B%0A            context.response().setStatusCode(500);%0A            context.response().putHeader(%22content-type%22, ContentType.APPLICATION_JSON.toString());%0A%0A            data = new JSONObject();%0A%0A            data.put(%22exception%22, exception.getClass().getCanonicalName());%0A            data.put(%22message%22, exception.getMessage());%0A%0A            context.response().end(data.toString(4));%0A%0A            return;%0A        %7D
 %0A%0A  
@@ -1218,24 +1218,24 @@
 4));%0A    %7D%0A%0A
-
     protecte
@@ -1289,12 +1289,29 @@
 request)
+ throws Exception
 ;%0A%7D%0A

Handle API errors gracefully