]> source.dussan.org Git - jgit.git/commitdiff
Add response message, if any, on HTTP status 404 57/125357/3
authorThomas Wolf <thomas.wolf@paranor.ch>
Tue, 3 Jul 2018 06:46:12 +0000 (08:46 +0200)
committerThomas Wolf <thomas.wolf@paranor.ch>
Tue, 3 Jul 2018 11:54:32 +0000 (13:54 +0200)
Try to give as much information as possible. The connection's
response message might contain additional hints as to why the
connection could not be established.

Bug: 536541
Change-Id: I7230e4e0be9417be8cedeb8aaab35186fcbf00a5
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/HttpClientTests.java
org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties
org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java
org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportHttp.java

index ef059bf2a34aac3b07cd930415516b888df62ffb..61f272c4cd06758734e58b8c1c648d4ef6725fc2 100644 (file)
@@ -175,7 +175,9 @@ public class HttpClientTests extends HttpTestCase {
                        } catch (NoRemoteRepositoryException err) {
                                String exp = uri + ": " + uri
                                                + "/info/refs?service=git-upload-pack not found";
-                               assertEquals(exp, err.getMessage());
+                               assertNotNull(err.getMessage());
+                               assertTrue("Unexpected error message",
+                                               err.getMessage().startsWith(exp));
                        }
                }
        }
@@ -191,7 +193,9 @@ public class HttpClientTests extends HttpTestCase {
                        } catch (NoRemoteRepositoryException err) {
                                String exp = uri + ": " + uri
                                                + "/info/refs?service=git-upload-pack not found";
-                               assertEquals(exp, err.getMessage());
+                               assertNotNull(err.getMessage());
+                               assertTrue("Unexpected error message",
+                                               err.getMessage().startsWith(exp));
                        }
                }
        }
index 809bdf2865a16f6ccdb3ca88ced4cbbff3e4fbd9..ee5ba20b2921d875a3803e098e1a7143e13d46be 100644 (file)
@@ -755,8 +755,8 @@ updatingRefFailed=Updating the ref {0} to {1} failed. ReturnCode from RefUpdate.
 upstreamBranchName=branch ''{0}'' of {1}
 uriNotConfigured=Submodule URI not configured
 uriNotFound={0} not found
+uriNotFoundWithMessage={0} not found: {1}
 URINotSupported=URI not supported: {0}
-URLNotFound={0} not found
 userConfigFileInvalid=User config file {0} invalid {1}
 walkFailure=Walk failure.
 wantNotValid=want {0} not valid
index f3029bf3a13438e5209cfcc6544c93f8df8a0e1d..7c29d4d13be44c62e8edc1148bf163088563c366 100644 (file)
@@ -816,8 +816,8 @@ public class JGitText extends TranslationBundle {
        /***/ public String upstreamBranchName;
        /***/ public String uriNotConfigured;
        /***/ public String uriNotFound;
+       /***/ public String uriNotFoundWithMessage;
        /***/ public String URINotSupported;
-       /***/ public String URLNotFound;
        /***/ public String userConfigFileInvalid;
        /***/ public String walkFailure;
        /***/ public String wantNotValid;
index c08f4003079f8a58ceb0874fab1e6168a6bd2d7f..ee64a87f764c0fde17598bd4bccf16c5d2fbdcfb 100644 (file)
@@ -483,6 +483,18 @@ public class TransportHttp extends HttpTransport implements WalkTransport,
                this.headers = headers;
        }
 
+       private NoRemoteRepositoryException createNotFoundException(URIish u,
+                       URL url, String msg) {
+               String text;
+               if (msg != null && !msg.isEmpty()) {
+                       text = MessageFormat.format(JGitText.get().uriNotFoundWithMessage,
+                                       url, msg);
+               } else {
+                       text = MessageFormat.format(JGitText.get().uriNotFound, url);
+               }
+               return new NoRemoteRepositoryException(u, text);
+       }
+
        private HttpConnection connect(String service)
                        throws TransportException, NotSupportedException {
                URL u = getServiceURL(service);
@@ -511,8 +523,8 @@ public class TransportHttp extends HttpTransport implements WalkTransport,
                                        return conn;
 
                                case HttpConnection.HTTP_NOT_FOUND:
-                                       throw new NoRemoteRepositoryException(uri,
-                                                       MessageFormat.format(JGitText.get().uriNotFound, u));
+                                       throw createNotFoundException(uri, u,
+                                                       conn.getResponseMessage());
 
                                case HttpConnection.HTTP_UNAUTHORIZED:
                                        authMethod = HttpAuthMethod.scanResponse(conn, ignoreTypes);
@@ -1180,9 +1192,8 @@ public class TransportHttp extends HttpTransport implements WalkTransport,
                                                return;
 
                                        case HttpConnection.HTTP_NOT_FOUND:
-                                               throw new NoRemoteRepositoryException(uri,
-                                                               MessageFormat.format(JGitText.get().uriNotFound,
-                                                                               conn.getURL()));
+                                               throw createNotFoundException(uri, conn.getURL(),
+                                                               conn.getResponseMessage());
 
                                        case HttpConnection.HTTP_FORBIDDEN:
                                                throw new TransportException(uri,