Source:
public void handleError(HttpCommand command, HttpResponse response) { Exception exception = null; try { String message = parseMessage(response); message = message != null ? message : String.format("%s -> %s", command.getCurrentRequest().getRequestLine(), response.getStatusLine()); switch (response.getStatusCode()) { case 401: exception = new AuthorizationException(message, exception); break; case 404: if (command.getCurrentRequest().getMethod().equals("GET")) { if (command.getCurrentRequest().getEndpoint().getPath().endsWith("/images/json")) { exception = new HttpResponseException("Unable to reach docker daemon", command, response); } } break; case 409: if (command.getCurrentRequest().getMethod().equals("POST")) { if (command.getCurrentRequest().getEndpoint().getPath().endsWith("/containers")) { exception = new HttpResponseException("Container already exists", command, response); } } break; case 500: if (command.getCurrentRequest().getMethod().equals("POST")) { if (command.getCurrentRequest().getEndpoint().getPath().endsWith("/engines")) { exception = new HttpResponseException("Connection refused registering docker daemon", command, response); } } else if (command.getCurrentRequest().getMethod().equals("DELETE")) { if (command.getCurrentRequest().getEndpoint().getPath().endsWith("/servicekeys")) { exception = new HttpResponseException("ServiceKey does not exist", command, response); } } break; default: exception = new HttpResponseException(message, command, response); break; } } catch (Exception e) { exception = new HttpResponseException(command, response, e); } finally { closeQuietly(response.getPayload()); command.setException(exception); } }

Target:
public void handleError(HttpCommand command, HttpResponse response) { String message = parseMessage(response); Exception exception = null; try { message = message != null ? message : String.format("%s -> %s", command.getCurrentRequest().getRequestLine(), response.getStatusLine()); switch (response.getStatusCode()) { case 401: exception = new AuthorizationException(message, exception); break; case 404: if (command.getCurrentRequest().getMethod().equals("GET")) { if (command.getCurrentRequest().getEndpoint().getPath().endsWith("/images/json")) exception = new HttpResponseException("Unable to reach docker daemon", command, response); } break; case 409: if (command.getCurrentRequest().getMethod().equals("POST")) { if (command.getCurrentRequest().getEndpoint().getPath().endsWith("/containers")) exception = new HttpResponseException("Container already exists", command, response); } break; case 500: if (command.getCurrentRequest().getMethod().equals("POST")) { if (command.getCurrentRequest().getEndpoint().getPath().endsWith("/engines")) exception = new HttpResponseException("Connection refused registering docker daemon", command, response); } else if (command.getCurrentRequest().getMethod().equals("DELETE")) { if (command.getCurrentRequest().getEndpoint().getPath().endsWith("/servicekeys") && message.contains("service key does not exist")) { exception = new ResourceNotFoundException(message, new HttpResponseException(command, response, message)); } } break; default: exception = new HttpResponseException(message, command, response); break; } } catch (Exception e) { exception = new HttpResponseException(command, response, e); } finally { if (exception == null) { exception = message != null ? new HttpResponseException(command, response, message) : new HttpResponseException(command, response); } closeQuietly(response.getPayload()); command.setException(exception); } }