Source:
<code>private FullHttpResponse getErrorResponse(Throwable cause) { HttpResponseStatus status; RestServiceErrorCode restServiceErrorCode = null; String errReason = null; if (cause instanceof RestServiceException) { restServiceErrorCode = ((RestServiceException) cause).getErrorCode(); errorResponseStatus = ResponseStatus.getResponseStatus(restServiceErrorCode); status = getHttpResponseStatus(errorResponseStatus); if (status == HttpResponseStatus.BAD_REQUEST) { errReason = new String( Utils.getRootCause(cause).getMessage().replaceAll("[\n\t\r]", " ").getBytes(StandardCharsets.US_ASCII), StandardCharsets.US_ASCII); } <START> } else if (Utils.isPossibleClientTerminate(cause)) { <END> nettyMetrics.clientEarlyTerminateCount.inc(); status = HttpResponseStatus.INTERNAL_SERVER_ERROR; errorResponseStatus = ResponseStatus.InternalServerError; } else { nettyMetrics.internalServerErrorCount.inc(); status = HttpResponseStatus.INTERNAL_SERVER_ERROR; errorResponseStatus = ResponseStatus.InternalServerError; } logger.trace("Constructed error response for the client - [{} - {}]", status, errReason); FullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, status); response.headers().set(HttpHeaderNames.DATE, new GregorianCalendar().getTime()); HttpUtil.setContentLength(response, 0); if (errReason != null) { response.headers().set(FAILURE_REASON_HEADER, errReason); } if (restServiceErrorCode != null && HttpStatusClass.CLIENT_ERROR.contains(status.code())) { response.headers().set(ERROR_CODE_HEADER, restServiceErrorCode.name()); } response.headers().set(HttpHeaderNames.CONTENT_TYPE, "text/plain; charset=UTF-8"); boolean keepAlive = !forceClose && HttpUtil.isKeepAlive(responseMetadata) && request != null && !request.getRestMethod() .equals(RestMethod.POST) && !request.getRestMethod().equals(RestMethod.PUT) && !CLOSE_CONNECTION_ERROR_STATUSES.contains(status); HttpUtil.setKeepAlive(response, keepAlive); return response; }</code><technical_language>minor: "client termination"? ("terminate" sounds a bit odd a noun)</technical_language>

Target:
private FullHttpResponse getErrorResponse(Throwable cause) { HttpResponseStatus status; RestServiceErrorCode restServiceErrorCode = null; String errReason = null; if (cause instanceof RestServiceException) { restServiceErrorCode = ((RestServiceException) cause).getErrorCode(); errorResponseStatus = ResponseStatus.getResponseStatus(restServiceErrorCode); status = getHttpResponseStatus(errorResponseStatus); if (status == HttpResponseStatus.BAD_REQUEST) { errReason = new String( Utils.getRootCause(cause).getMessage().replaceAll("[\n\t\r]", " ").getBytes(StandardCharsets.US_ASCII), StandardCharsets.US_ASCII); } } else if (Utils.isPossibleClientTermination(cause)) { nettyMetrics.clientEarlyTerminationCount.inc(); status = HttpResponseStatus.INTERNAL_SERVER_ERROR; errorResponseStatus = ResponseStatus.InternalServerError; } else { nettyMetrics.internalServerErrorCount.inc(); status = HttpResponseStatus.INTERNAL_SERVER_ERROR; errorResponseStatus = ResponseStatus.InternalServerError; } logger.trace("Constructed error response for the client - [{} - {}]", status, errReason); FullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, status); response.headers().set(HttpHeaderNames.DATE, new GregorianCalendar().getTime()); HttpUtil.setContentLength(response, 0); if (errReason != null) { response.headers().set(FAILURE_REASON_HEADER, errReason); } if (restServiceErrorCode != null && HttpStatusClass.CLIENT_ERROR.contains(status.code())) { response.headers().set(ERROR_CODE_HEADER, restServiceErrorCode.name()); } response.headers().set(HttpHeaderNames.CONTENT_TYPE, "text/plain; charset=UTF-8"); boolean keepAlive = !forceClose && HttpUtil.isKeepAlive(responseMetadata) && request != null && !request.getRestMethod() .equals(RestMethod.POST) && !request.getRestMethod().equals(RestMethod.PUT) && !CLOSE_CONNECTION_ERROR_STATUSES.contains(status); HttpUtil.setKeepAlive(response, keepAlive); return response; }