Source:
<code>public HttpConnection execute(HttpConnection connection) { connection.connectionFactory = factory; connection.requestProperties.put("Accept", "application/json"); connection.responseInterceptors.addAll(this.responseInterceptors); connection.requestInterceptors.addAll(this.requestInterceptors); InputStream es = null; try { connection = connection.execute(); int code = connection.getConnection().getResponseCode(); String response = connection.getConnection().getResponseMessage(); if (code / 100 == 2) { return connection; } else { final CouchDbException ex; switch (code) { case HttpURLConnection.HTTP_NOT_FOUND: ex = new NoDocumentException(response); break; case HttpURLConnection.HTTP_CONFLICT: ex = new DocumentConflictException(response); break; case HttpURLConnection.HTTP_PRECON_FAILED: ex = new PreconditionFailedException(response); break; default: ex = new CouchDbException(response, code); break; } es = connection.getConnection().getErrorStream(); if (es != null) { Class<? extends CouchDbException> exceptionClass = ex.getClass(); try { Gson g = new GsonBuilder().registerTypeAdapter(exceptionClass, new InstanceCreator<CouchDbException>() { @Override public CouchDbException createInstance(Type type) { return ex; } }).create(); <START> g.fromJson(new InputStreamReader(es), <END> exceptionClass); } catch (JsonParseException e) { } } throw ex; } } catch (IOException ioe) { throw new CouchDbException("Error retrieving server response", ioe); } finally { close(es); } }</code><technical_language>attempt return part of response if deserialise it? instances error returned JSON HAProxy return HTML error messages. This for another PR though</technical_language>

Target:
public HttpConnection execute(HttpConnection connection) { connection.connectionFactory = factory; connection.requestProperties.put("Accept", "application/json"); connection.responseInterceptors.addAll(this.responseInterceptors); connection.requestInterceptors.addAll(this.requestInterceptors); InputStream es = null; try { connection = connection.execute(); int code = connection.getConnection().getResponseCode(); String response = connection.getConnection().getResponseMessage(); if (code / 100 == 2) { return connection; } else { final CouchDbException ex; switch (code) { case HttpURLConnection.HTTP_NOT_FOUND: ex = new NoDocumentException(response); break; case HttpURLConnection.HTTP_CONFLICT: ex = new DocumentConflictException(response); break; case HttpURLConnection.HTTP_PRECON_FAILED: ex = new PreconditionFailedException(response); break; default: ex = new CouchDbException(response, code); break; } es = connection.getConnection().getErrorStream(); if (es != null) { byte[] errorResponse = IOUtils.toByteArray(es); Class<? extends CouchDbException> exceptionClass = ex.getClass(); try { Gson g = new GsonBuilder().registerTypeAdapter(exceptionClass, new InstanceCreator<CouchDbException>() { @Override public CouchDbException createInstance(Type type) { return ex; } }).create(); g.fromJson(new InputStreamReader(new ByteArrayInputStream(errorResponse), "UTF-8"), exceptionClass); } catch (JsonParseException e) { ex.error = new String(errorResponse, "UTF-8"); } } throw ex; } } catch (IOException ioe) { throw new CouchDbException("Error retrieving server response", ioe); } finally { close(es); } }