private boolean maybeSendErrorResponse(Exception exception) {
    long processingStartTime = System.currentTimeMillis();
    boolean responseSent = false;
    logger.trace("Sending error response to client on channel {}", ctx.channel());
    FullHttpResponse errorResponse = getErrorResponse(exception);
    if (maybeWriteResponseMetadata(errorResponse, new ErrorResponseWriteListener())) {
      logger.trace("Scheduled error response sending on channel {}", ctx.channel());
      responseStatus = errorResponseStatus;
      responseSent = true;
      long processingTime = System.currentTimeMillis() - processingStartTime;
      nettyMetrics.errorResponseProcessingTimeInMs.update(processingTime);
    } else {
      logger.debug("Could not send error response on channel {}", ctx.channel());
    }
    return responseSent;
  }
Builds and sends an error response to the client based on {@code cause}.
@param exception the cause of the request handling failure.
@return {@code true} if error response was scheduled to be sent. {@code false} otherwise.
ambry-rest/src/main/java/com/github/ambry/rest/NettyResponseChannel.java