public void handle(ServletResponse response, Exception ex) throws IOException {
        if (ex instanceof InterceptException) {
            if (response instanceof org.eclipse.jetty.server.Response) {
                String errorData = ObjectMapperFactory
                        .getMapper().writer().writeValueAsString(new ErrorData(ex.getMessage()));
                byte[] errorBytes = errorData.getBytes(StandardCharsets.UTF_8);
                int errorCode = ((InterceptException) ex).getErrorCode();
                HttpFields httpFields = new HttpFields();
                HttpField httpField = new HttpField(HttpHeader.CONTENT_TYPE, "application/json;charset=utf-8");
                httpFields.add(httpField);
                MetaData.Response info = new MetaData.Response(HttpVersion.HTTP_1_1, errorCode, httpFields);
                info.setHttpVersion(HttpVersion.HTTP_1_1);
                info.setReason(errorData);
                info.setStatus(errorCode);
                info.setContentLength(errorBytes.length);
                ((org.eclipse.jetty.server.Response) response).getHttpChannel().sendResponse(info,
                        ByteBuffer.wrap(errorBytes),
                        true);
            } else {
                ((HttpServletResponse) response).sendError(((InterceptException) ex).getErrorCode(),
                        ex.getMessage());
            }
        } else {
            ((HttpServletResponse) response).sendError(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
                    ex.getMessage());
        }
    }
@Test
    @SneakyThrows
    public void testHandle() {
        String restriction = "Reach the max tenants [5] restriction";
        String internal = "internal exception";
        String illegal = "illegal argument exception ";
        ExceptionHandler handler = new ExceptionHandler();
        HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
        handler.handle(response, new InterceptException(PRECONDITION_FAILED_412, restriction));
        Mockito.verify(response).sendError(PRECONDITION_FAILED_412, restriction);

        handler.handle(response, new InterceptException(INTERNAL_SERVER_ERROR_500, internal));
        Mockito.verify(response).sendError(INTERNAL_SERVER_ERROR_500, internal);

        handler.handle(response, new IllegalArgumentException(illegal));
        Mockito.verify(response).sendError(INTERNAL_SERVER_ERROR_500, illegal);

        Response response2 = Mockito.mock(Response.class);
        HttpChannel httpChannel = Mockito.mock(HttpChannel.class);
        Mockito.when(response2.getHttpChannel()).thenReturn(httpChannel);
        handler.handle(response2, new InterceptException(PRECONDITION_FAILED_412, restriction));
        Mockito.verify(httpChannel).sendResponse(Mockito.any(), Mockito.any(), Mockito.anyBoolean());
    }