Просмотр исходного кода

Send the MissingRepositoryException message to the client

Michael Walker 8 лет назад
Родитель
Сommit
3a374e0ba7

+ 5 - 4
services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/server/Oauth2Filter.java

@@ -78,7 +78,7 @@ public class Oauth2Filter implements Filter {
             );
             );
             return;
             return;
         } catch (MissingRepositoryException e) {
         } catch (MissingRepositoryException e) {
-            missing(project, (HttpServletResponse) servletResponse);
+            missing(project, e, (HttpServletResponse) servletResponse);
         }
         }
         Log.info("[{}] Auth not needed", project);
         Log.info("[{}] Auth not needed", project);
         filterChain.doFilter(servletRequest, servletResponse);
         filterChain.doFilter(servletRequest, servletResponse);
@@ -205,6 +205,7 @@ public class Oauth2Filter implements Filter {
 
 
     private void missing(
     private void missing(
             String projectName,
             String projectName,
+            MissingRepositoryException e,
             HttpServletResponse response
             HttpServletResponse response
     ) throws IOException {
     ) throws IOException {
         Log.info("[{}] Project missing.", projectName);
         Log.info("[{}] Project missing.", projectName);
@@ -216,9 +217,9 @@ public class Oauth2Filter implements Filter {
         response.setStatus(404);
         response.setStatus(404);
 
 
         PrintWriter w = response.getWriter();
         PrintWriter w = response.getWriter();
-        w.println("This project is not accessible over Git.");
-        w.println();
-        w.println("If you think this is an error, contact support at support@overleaf.com.");
+        for (String line : e.getDescriptionLines()) {
+            w.println(line);
+        }
         w.close();
         w.close();
     }
     }
 }
 }

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

@@ -8,12 +8,21 @@ import java.util.List;
 
 
 public class MissingRepositoryException extends SnapshotAPIException {
 public class MissingRepositoryException extends SnapshotAPIException {
 
 
+    private String message = "";
+
+    public MissingRepositoryException() {
+    }
+
+    public MissingRepositoryException(String message) {
+        this.message = message;
+    }
+
     @Override
     @Override
     public void fromJSON(JsonElement json) {}
     public void fromJSON(JsonElement json) {}
 
 
     @Override
     @Override
     public String getMessage() {
     public String getMessage() {
-        return "project not accessible over git";
+        return message;
     }
     }
 
 
     @Override
     @Override

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

@@ -73,9 +73,14 @@ public abstract class Request<T extends Result> {
                 int sc = httpCause.getStatusCode();
                 int sc = httpCause.getStatusCode();
                 if (sc == HttpServletResponse.SC_UNAUTHORIZED || sc == HttpServletResponse.SC_FORBIDDEN) {
                 if (sc == HttpServletResponse.SC_UNAUTHORIZED || sc == HttpServletResponse.SC_FORBIDDEN) {
                     throw new ForbiddenException();
                     throw new ForbiddenException();
-                }
-                if (sc >= 400 && sc < 500) {
+                } else if (sc == HttpServletResponse.SC_NOT_FOUND) {
                     throw new MissingRepositoryException();
                     throw new MissingRepositoryException();
+                } 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 FailedConnectionException(cause);
                 throw new FailedConnectionException(cause);
             } else {
             } else {