Sfoglia il codice sorgente

Display a more specific message for v2 projects

Michael Walker 8 anni fa
parent
commit
44d3ddd9aa

+ 10 - 0
services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/snapshot/base/MissingRepositoryException.java

@@ -8,6 +8,16 @@ import java.util.List;
 
 
 public class MissingRepositoryException extends SnapshotAPIException {
 public class MissingRepositoryException extends SnapshotAPIException {
 
 
+    public static final String GENERIC_REASON =
+        "This Overleaf project currently has no git access.\n" +
+        "\n" +
+        "If you think this is an error, contact support at support@overleaf.com.";
+
+    public static final String EXPORTED_TO_V2 =
+        "This Overleaf project has been moved to Overleaf v2, and git access is temporarily unsupported.\n" +
+        "\n" +
+        "See https://www.overleaf.com/help/342 for more information.";
+
     private String message = "";
     private String message = "";
 
 
     public MissingRepositoryException() {
     public MissingRepositoryException() {

+ 15 - 5
services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/snapshot/base/Request.java

@@ -2,6 +2,7 @@ package uk.ac.ic.wlgitbridge.snapshot.base;
 
 
 import com.google.api.client.http.*;
 import com.google.api.client.http.*;
 import com.google.gson.JsonElement;
 import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
 import com.ning.http.client.AsyncHttpClient;
 import com.ning.http.client.AsyncHttpClient;
 import uk.ac.ic.wlgitbridge.snapshot.exception.FailedConnectionException;
 import uk.ac.ic.wlgitbridge.snapshot.exception.FailedConnectionException;
 import uk.ac.ic.wlgitbridge.util.Instance;
 import uk.ac.ic.wlgitbridge.util.Instance;
@@ -74,13 +75,22 @@ public abstract class Request<T extends Result> {
                 if (sc == HttpServletResponse.SC_UNAUTHORIZED || sc == HttpServletResponse.SC_FORBIDDEN) {
                 if (sc == HttpServletResponse.SC_UNAUTHORIZED || sc == HttpServletResponse.SC_FORBIDDEN) {
                     throw new ForbiddenException();
                     throw new ForbiddenException();
                 } else if (sc == HttpServletResponse.SC_NOT_FOUND) {
                 } else if (sc == HttpServletResponse.SC_NOT_FOUND) {
+                    try {
+                        JsonObject json = Instance.gson.fromJson(httpCause.getContent(), JsonObject.class);
+                        String message = json.get("message").getAsString();
+
+                        if ("Exported to v2".equals(message)) {
+                            throw new MissingRepositoryException(MissingRepositoryException.EXPORTED_TO_V2);
+                        }
+                    } catch (IllegalStateException
+                            | ClassCastException
+                            | NullPointerException _) {
+                        // disregard any errors that arose while handling the JSON
+                    }
+
                     throw new MissingRepositoryException();
                     throw new MissingRepositoryException();
                 } else if (sc >= 400 && sc < 500) {
                 } else if (sc >= 400 && sc < 500) {
-                    throw new MissingRepositoryException(
-                        "This project is currently inaccessible over Git.\n" +
-                        "\n" +
-                        "If you think this is an error, contact support at support@overleaf.com."
-                    );
+                    throw new MissingRepositoryException(MissingRepositoryException.GENERIC_REASON);
                 }
                 }
                 throw new FailedConnectionException(cause);
                 throw new FailedConnectionException(cause);
             } else {
             } else {