jira-importer opened a new issue, #971: URL: https://github.com/apache/httpcomponents-core/issues/971
**[Gary D. Gregory](https://issues.apache.org/jira/secure/ViewProfile.jspa?name=garydgregory)** opened **[HTTPCORE-468](https://issues.apache.org/jira/browse/HTTPCORE-468?redirect=false)** and commented As a developer, I would like to allow my `HttpAsyncService` subclasses to customize the HTTP status code. I propose to refactor the method `org.apache.http.nio.protocol.HttpAsyncService.handleException(Exception, HttpContext)` like so: ``` diff --git a/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncService.java b/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncService.java index f941399..789b304 100644 --- a/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncService.java +++ b/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncService.java @@ -614,6 +614,17 @@ protected HttpAsyncResponseProducer handleException( final Exception ex, final HttpContext context) { + String message = ex.getMessage(); + if (message == null) { + message = ex.toString(); + } + final HttpResponse response = this.responseFactory.newHttpResponse(HttpVersion.HTTP_1_1, + toStatusCode(ex, context), context); + return new ErrorResponseProducer(response, + new NStringEntity(message, ContentType.DEFAULT_TEXT), false); + } + + protected int toStatusCode(final Exception ex, final HttpContext context) { final int code; if (ex instanceof MethodNotSupportedException) { code = HttpStatus.SC_NOT_IMPLEMENTED; @@ -624,14 +635,7 @@ } else { code = HttpStatus.SC_INTERNAL_SERVER_ERROR; } - String message = ex.getMessage(); - if (message == null) { - message = ex.toString(); - } - final HttpResponse response = this.responseFactory.newHttpResponse(HttpVersion.HTTP_1_1, - code, context); - return new ErrorResponseProducer(response, - new NStringEntity(message, ContentType.DEFAULT_TEXT), false); + return code; } /** ``` As in `dev/4.4.x/HTTPCORE-468`. --- **Affects:** 4.4.6 **Backported to:** [4.4.7](https://github.com/apache/httpcomponents-core/milestone/44?closed=1) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
