HttpClientTransport has the following code:
private Response execute(HttpUriRequest request) {
try {
beforeExecute(request);
ClassicHttpResponse response = this.client.executeOpen(this.host, request, null);
int statusCode = response.getCode();
if (statusCode >= 400 && statusCode <= 500) {
byte[] content = readContent(response);
response.close();
Errors errors = (statusCode != 500) ? deserializeErrors(content) : null;
Message message = deserializeMessage(content);
throw new DockerEngineException(this.host.toHostString(), request.getUri(), statusCode,
response.getReasonPhrase(), errors, message);
}
return new HttpClientResponse(response);
}
catch (IOException | URISyntaxException ex) {
throw new DockerConnectionException(this.host.toHostString(), ex);
}
}
But it appears that Docker returns 407 response with a plain text message when Enforced Sign-In is required. It would be helpful if we could surface that error.
Comment From: Tejas-Teju
Can I work on this @philwebb?
We can fall back to plain text if deserialization fails.
Comment From: cvsnehankita
Hi Team,
I can see that deserialization is already implemented here for status code between 500 and 600, Message message = deserializeMessage(content);
One approach I would like to suggest is adding an if case for status code 407 to throw a custom ProxyAuthenticationException. please try implementing below,
private Response execute(HttpUriRequest request) { try { beforeExecute(request); ClassicHttpResponse response = this.client.executeOpen(this.host, request, null); int statusCode = response.getCode(); if (statusCode >= 400 && statusCode <= 500) { byte[] content = readContent(response);
// handle 407 Proxy Authentication Required exception
if (statusCode == 407) {
response.close();
throw new ProxyAuthenticationException(
"Proxy authentication required for host: " + this.host.toHostString() + ", URI: " + request.getUri());
}
response.close();
Errors errors = (statusCode != 500) ? deserializeErrors(content) : null;
Message message = deserializeMessage(content);
throw new DockerEngineException(this.host.toHostString(), request.getUri(), statusCode,
response.getReasonPhrase(), errors, message);
}
return new HttpClientResponse(response);
}
catch (IOException | URISyntaxException ex) {
throw new DockerConnectionException(this.host.toHostString(), ex);
}
}
Custom exception we can implement as below public class ProxyAuthenticationException extends RuntimeException { public ProxyAuthenticationException(String message) { super(message); } }
Comment From: philwebb
Closing in favor of PR #47180. Thanks @siva-sai-udaygiri!