Send the MissingRepositoryException message to the client

This commit is contained in:
Michael Walker 2018-02-06 14:11:28 +00:00
parent 82c0873743
commit 3a374e0ba7
3 changed files with 22 additions and 7 deletions

View file

@ -78,7 +78,7 @@ public class Oauth2Filter implements Filter {
);
return;
} catch (MissingRepositoryException e) {
missing(project, (HttpServletResponse) servletResponse);
missing(project, e, (HttpServletResponse) servletResponse);
}
Log.info("[{}] Auth not needed", project);
filterChain.doFilter(servletRequest, servletResponse);
@ -205,6 +205,7 @@ public class Oauth2Filter implements Filter {
private void missing(
String projectName,
MissingRepositoryException e,
HttpServletResponse response
) throws IOException {
Log.info("[{}] Project missing.", projectName);
@ -216,9 +217,9 @@ public class Oauth2Filter implements Filter {
response.setStatus(404);
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();
}
}

View file

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

View file

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