You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by GitBox <gi...@apache.org> on 2019/12/11 09:28:43 UTC

[GitHub] [sling-org-apache-sling-committer-cli] rombert commented on a change in pull request #6: SLING-8864 - Report authentication errors immediately without looking at the response's body

rombert commented on a change in pull request #6: SLING-8864 - Report authentication errors immediately without looking at the response's body
URL: https://github.com/apache/sling-org-apache-sling-committer-cli/pull/6#discussion_r356481884
 
 

 ##########
 File path: src/main/java/org/apache/sling/cli/impl/http/HttpClientFactory.java
 ##########
 @@ -61,9 +67,18 @@ protected void activate(ComponentContext ctx) {
     }
 
     public CloseableHttpClient newClient() {
-        
+        final AtomicReference<String> url = new AtomicReference<>();
         return HttpClients.custom()
                 .setDefaultCredentialsProvider(newCredentialsProvider())
+                .addInterceptorFirst(
+                        (HttpRequestInterceptor) (request, context) ->
+                        url.set(((HttpRequestWrapper) request).getOriginal().getRequestLine().getUri())
+                )
+                .addInterceptorFirst((HttpResponseInterceptor) (response, context) -> {
+                    if (response.getStatusLine().getStatusCode() == HttpStatus.SC_UNAUTHORIZED) {
+                        throw new IllegalStateException("Please check your authentication details for " + url.get());
 
 Review comment:
   Would be good to also add something like "Server returned a 401 status"

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services