Report all 4xx from write-latex API as MissingRepositoryException

This commit is contained in:
Michael Walker 2018-02-06 13:30:30 +00:00
parent 6ae6acd826
commit 82c0873743
3 changed files with 45 additions and 8 deletions

View file

@ -70,14 +70,12 @@ public abstract class Request<T extends Result> {
Throwable cause = e.getCause();
if (cause instanceof HttpResponseException) {
HttpResponseException httpCause = (HttpResponseException) cause;
switch (httpCause.getStatusCode()) {
case HttpServletResponse.SC_UNAUTHORIZED:
case HttpServletResponse.SC_FORBIDDEN:
throw new ForbiddenException();
case HttpServletResponse.SC_GONE:
throw new MissingRepositoryException();
default:
break;
int sc = httpCause.getStatusCode();
if (sc == HttpServletResponse.SC_UNAUTHORIZED || sc == HttpServletResponse.SC_FORBIDDEN) {
throw new ForbiddenException();
}
if (sc >= 400 && sc < 500) {
throw new MissingRepositoryException();
}
throw new FailedConnectionException(cause);
} else {

View file

@ -48,6 +48,9 @@ public class WLGitBridgeIntegrationTest {
put("cannotCloneADisabledProject", new HashMap<String, SnapshotAPIState>() {{
put("state", new SnapshotAPIStateBuilder(getResourceAsStream("/cannotCloneADisabledProject/state/state.json")).build());
}});
put("cannotCloneAMissingProject", new HashMap<String, SnapshotAPIState>() {{
put("state", new SnapshotAPIStateBuilder(getResourceAsStream("/cannotCloneAMissingProject/state/state.json")).build());
}});
put("canPullAModifiedTexFile", new HashMap<String, SnapshotAPIState>() {{
put("base", new SnapshotAPIStateBuilder(getResourceAsStream("/canPullAModifiedTexFile/base/state.json")).build());
put("withModifiedTexFile", new SnapshotAPIStateBuilder(getResourceAsStream("/canPullAModifiedTexFile/withModifiedTexFile/state.json")).build());
@ -748,6 +751,24 @@ public class WLGitBridgeIntegrationTest {
assertNotEquals(0, gitProcess.waitFor());
}
@Test
public void cannotCloneAMissingProject() throws IOException, GitAPIException, InterruptedException {
int gitBridgePort = 33880;
int mockServerPort = 3880;
MockSnapshotServer server = new MockSnapshotServer(mockServerPort, getResource("/cannotCloneAMissingProject").toFile());
server.start();
server.setState(states.get("cannotCloneAMissingProject").get("state"));
GitBridgeApp wlgb = new GitBridgeApp(new String[] {
makeConfigFile(gitBridgePort, mockServerPort)
});
wlgb.run();
Process gitProcess = runtime.exec("git clone http://127.0.0.1:" + gitBridgePort + "/testproj.git", null, dir);
wlgb.stop();
assertNotEquals(0, gitProcess.waitFor());
}
private String makeConfigFile(
int port,
int apiPort

View file

@ -0,0 +1,18 @@
[
{
"project": "missing",
"getDoc": {
"error": 404,
"versionID": 1,
"createdAt": "2018-02-06T13:29:00Z",
"email": "michael.walker@overleaf.com",
"name": "msw"
},
"getSavedVers": [],
"getForVers": [],
"push": "success",
"postback": {
"type": "outOfDate"
}
}
]