Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id CD524200B9C for ; Mon, 10 Oct 2016 22:12:22 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id CC369160AD1; Mon, 10 Oct 2016 20:12:22 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id E374C160AE1 for ; Mon, 10 Oct 2016 22:12:21 +0200 (CEST) Received: (qmail 69880 invoked by uid 500); 10 Oct 2016 20:12:20 -0000 Mailing-List: contact dev-help@hc.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "HttpComponents Project" Delivered-To: mailing list dev@hc.apache.org Received: (qmail 69855 invoked by uid 99); 10 Oct 2016 20:12:20 -0000 Received: from arcas.apache.org (HELO arcas) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 10 Oct 2016 20:12:20 +0000 Received: from arcas.apache.org (localhost [127.0.0.1]) by arcas (Postfix) with ESMTP id 79CD32C0B04 for ; Mon, 10 Oct 2016 20:12:20 +0000 (UTC) Date: Mon, 10 Oct 2016 20:12:20 +0000 (UTC) From: "Sandeep Kaul (JIRA)" To: dev@hc.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (HTTPCLIENT-1756) Response Body on response codes over 300 should not be ignored MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 archived-at: Mon, 10 Oct 2016 20:12:23 -0000 [ https://issues.apache.org/jira/browse/HTTPCLIENT-1756?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15563345#comment-15563345 ] Sandeep Kaul commented on HTTPCLIENT-1756: ------------------------------------------ [~olegk] Is this something that can be patched? I am planning to fix this, and I'll start on it if this can be released. > Response Body on response codes over 300 should not be ignored > -------------------------------------------------------------- > > Key: HTTPCLIENT-1756 > URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1756 > Project: HttpComponents HttpClient > Issue Type: Improvement > Components: HttpClient (classic) > Affects Versions: 4.5.2 > Reporter: Michael Peter Gower > Priority: Minor > Fix For: Future > > > Hello. This is my first time posting an issue to this project. I've done my best to be helpful. > Many modern RESTful APIs (e.g. Amazon Web Services) will return a generic status description (e.g. "Bad Request") and details in the body of the response on an error (e.g. code 400). > However the org.apache.http.client.fluent.Response.returnContent() ignores the body (content) on a return code of over or equal to 300, causing the debugging information to be lost. This leads to generic exception messages. > A possible solution would be to include the body in the exception string, as demonstrated in the below ResponseHandler. > protected static class FaultTolerantContentResponseHandler > extends ContentResponseHandler { > @Override > public Content handleResponse(final HttpResponse response) > throws HttpResponseException, IOException { > final StatusLine statusLine = response.getStatusLine(); > final HttpEntity entity = response.getEntity(); > Content content = entity == null ? null : handleEntity(entity); > if (statusLine.getStatusCode() >= 300) { > String message = statusLine.getReasonPhrase(); > if (content != null) { > message += ", body was " + content.asString(); > } > throw new HttpResponseException(statusLine.getStatusCode(), > message); > } > return content; > } > } > Alternatives would be to create a new subclass of HttpResponseException that would have an additional getErrorContent() method to preserve backwards compatibility. -- This message was sent by Atlassian JIRA (v6.3.4#6332) --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org For additional commands, e-mail: dev-help@hc.apache.org