@Override
    public HttpResponse handle(HttpRequest request) {
        log.log(Level.FINE, () -> request.getMethod() + " " + request.getUri().toString());
        try {
            return switch (request.getMethod()) {
                case POST -> handlePOST(request);
                case GET -> handleGET(request);
                case PUT -> handlePUT(request);
                case DELETE -> handleDELETE(request);
                default -> createErrorResponse(request.getMethod());
            };
        } catch (NotFoundException | com.yahoo.vespa.config.server.NotFoundException e) {
            return HttpErrorResponse.notFoundError(getMessage(e, request));
        } catch (ActivationConflictException e) {
            return HttpErrorResponse.conflictWhenActivating(getMessage(e, request));
        } catch (InvalidApplicationException e) {
            return HttpErrorResponse.invalidApplicationPackage(getMessage(e, request));
        } catch (IllegalArgumentException | UnsupportedOperationException e) {
            return HttpErrorResponse.badRequest(getMessage(e, request));
        } catch (NodeAllocationException e) {
            return e.retryable() ? HttpErrorResponse.nodeAllocationFailure(getMessage(e, request))
                                 : HttpErrorResponse.invalidApplicationPackage(getMessage(e, request));
        } catch (InternalServerException e) {
            return HttpErrorResponse.internalServerError(getMessage(e, request));
        } catch (UnknownVespaVersionException e) {
            return HttpErrorResponse.unknownVespaVersion(getMessage(e, request));
        } catch (RequestTimeoutException e) {
            return HttpErrorResponse.requestTimeout(getMessage(e, request));
        } catch (ApplicationLockException e) {
            return HttpErrorResponse.applicationLockFailure(getMessage(e, request));
        } catch (ParentHostUnavailableException e) {
            return HttpErrorResponse.parentHostNotReady(getMessage(e, request));
        } catch (CertificateNotReadyException e) {
            return HttpErrorResponse.certificateNotReady(getMessage(e, request));
        } catch (ConfigNotConvergedException e) {
            return HttpErrorResponse.configNotConverged(getMessage(e, request));
        } catch (LoadBalancerServiceException e) {
            return HttpErrorResponse.loadBalancerNotReady(getMessage(e, request));
        } catch (ReindexingStatusException e) {
            return HttpErrorResponse.reindexingStatusUnavailable(getMessage(e, request));
        } catch (PreconditionFailedException e) {
            return HttpErrorResponse.preconditionFailed(getMessage(e, request));
        } catch (QuotaExceededException e) {
            return HttpErrorResponse.quotaExceeded(getMessage(e, request));
        } catch (Exception e) {
            log.log(Level.WARNING, "Unexpected exception handling a config server request", e);
            return HttpErrorResponse.internalServerError(getMessage(e, request));
        }
    }
@Test
    public void testResponse() throws IOException {
        final String message = "failed";
        HttpHandler httpHandler = new HttpTestHandler(new InvalidApplicationException(message));
        HttpResponse response = httpHandler.handle(HttpRequest.createTestRequest("foo", com.yahoo.jdisc.http.HttpRequest.Method.GET));
        assertEquals(Response.Status.BAD_REQUEST, response.getStatus());
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        response.render(baos);
        Slime data = SlimeUtils.jsonToSlime(baos.toByteArray());
        assertEquals(HttpErrorResponse.ErrorCode.INVALID_APPLICATION_PACKAGE.name(), data.get().field("error-code").asString());
        assertEquals(message, data.get().field("message").asString());
    }