public static void sendError(final ChannelHandlerContext ctx, final HttpResponseStatus status, final String message) {
        logger.warn(String.format("Invalid request - responding with %s and %s", status, message));
        errorMeter.mark();

        final ObjectNode node = mapper.createObjectNode();
        node.put("message", message);

        final FullHttpResponse response = new DefaultFullHttpResponse(
                HTTP_1_1, status, Unpooled.copiedBuffer(node.toString(), CharsetUtil.UTF_8));
        response.headers().set(CONTENT_TYPE, "application/json");
        HttpUtil.setContentLength(response, response.content().readableBytes());

        ctx.writeAndFlush(response);
    }
Helper method to send errors back as JSON. Only to be used when the RequestMessage couldn't be parsed, because
a proper serialized ResponseMessage should be sent in that case.

@param ctx           The netty channel context.
@param status        The HTTP error status code.
@param message       The error message to contain the body.
gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/handler/HttpHandlerUtil.java