From 3f85dc80f4a0f019865b59550e0d0c51bb758952 Mon Sep 17 00:00:00 2001 From: Shane Kilkelly Date: Tue, 11 Dec 2018 12:35:21 +0000 Subject: [PATCH] When user clone/pull/etc a project which doesn't exist, print a nice message The old behaviour was to just show an equivalent of a 500 error. This way, we catch the 404 from the API, and print an appropriate message to the user. --- .../git/handler/WLRepositoryResolver.java | 3 ++ .../base/MissingRepositoryException.java | 41 +++++++++---------- .../ic/wlgitbridge/snapshot/base/Request.java | 2 +- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/git/handler/WLRepositoryResolver.java b/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/git/handler/WLRepositoryResolver.java index 022101fc5b..6108078314 100644 --- a/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/git/handler/WLRepositoryResolver.java +++ b/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/git/handler/WLRepositoryResolver.java @@ -13,6 +13,7 @@ import uk.ac.ic.wlgitbridge.git.servlet.WLGitServlet; import uk.ac.ic.wlgitbridge.server.GitBridgeServer; import uk.ac.ic.wlgitbridge.server.Oauth2Filter; import uk.ac.ic.wlgitbridge.snapshot.base.ForbiddenException; +import uk.ac.ic.wlgitbridge.snapshot.base.MissingRepositoryException; import uk.ac.ic.wlgitbridge.util.Log; import uk.ac.ic.wlgitbridge.util.Util; @@ -97,6 +98,8 @@ public class WLRepositoryResolver } catch (ServiceNotEnabledException e) { cannot occur */ + } catch (MissingRepositoryException e) { + throw new ServiceMayNotContinueException(String.join("\n", e.getDescriptionLines()), e); } catch (ServiceMayNotContinueException e) { /* Such as FailedConnectionException */ throw e; diff --git a/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/snapshot/base/MissingRepositoryException.java b/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/snapshot/base/MissingRepositoryException.java index 9578c18f27..39d28e6b57 100644 --- a/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/snapshot/base/MissingRepositoryException.java +++ b/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/snapshot/base/MissingRepositoryException.java @@ -10,43 +10,40 @@ import java.util.List; public class MissingRepositoryException extends SnapshotAPIException { public static final List GENERIC_REASON = Arrays.asList( - "This Overleaf project currently has no git access.", + "This Overleaf project currently has no git access, either", + "because the project does not exist, or git access is not enabled for the project.", "", - "If this problem persists, please contact us." + "If this problem persists, please contact us at at support@overleaf.com" ); static List buildExportedToV2Message(String remoteUrl) { if (remoteUrl == null) { return Arrays.asList( - "This Overleaf project has been moved to Overleaf v2 and cannot be used with git at this time.", - "", - "If this error persists, please contact us at support@overleaf.com, or", - "see https://www.overleaf.com/help/342 for more information." + "This Overleaf project has been moved to Overleaf v2 and cannot be used with git at this time.", + "", + "If this error persists, please contact us at support@overleaf.com, or", + "see https://www.overleaf.com/help/342 for more information." ); } else { return Arrays.asList( - "This Overleaf project has been moved to Overleaf v2 and has a new identifier.", - "Please update your remote to:", - "", - " " + remoteUrl, - "", - "Assuming you are using the default \"origin\" remote, the following commands", - "will change the remote for you:", - "", - " git remote set-url origin " + remoteUrl, - "", - "If this does not work, please contact us at support@overleaf.com, or", - "see https://www.overleaf.com/help/342 for more information." + "This Overleaf project has been moved to Overleaf v2 and has a new identifier.", + "Please update your remote to:", + "", + " " + remoteUrl, + "", + "Assuming you are using the default \"origin\" remote, the following commands", + "will change the remote for you:", + "", + " git remote set-url origin " + remoteUrl, + "", + "If this does not work, please contact us at support@overleaf.com, or", + "see https://www.overleaf.com/help/342 for more information." ); } } private List descriptionLines; - public MissingRepositoryException() { - descriptionLines = new ArrayList(); - } - public MissingRepositoryException(List descriptionLines) { this.descriptionLines = descriptionLines; } diff --git a/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/snapshot/base/Request.java b/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/snapshot/base/Request.java index 65dc8af0b9..23c0b1d8f7 100644 --- a/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/snapshot/base/Request.java +++ b/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/snapshot/base/Request.java @@ -97,7 +97,7 @@ public abstract class Request { // disregard any errors that arose while handling the JSON } - throw new MissingRepositoryException(); + throw new MissingRepositoryException(MissingRepositoryException.GENERIC_REASON); } else if (sc >= 400 && sc < 500) { throw new MissingRepositoryException(MissingRepositoryException.GENERIC_REASON); }