Remove concept of fatal permanent exceptions

All exceptions will just cause the request to be tried again with some backoff.
This commit is contained in:
Torsten Grote
2021-12-15 16:54:04 -03:00
parent d665fc17ec
commit 9f1757ccaf
3 changed files with 16 additions and 47 deletions

View File

@@ -40,14 +40,5 @@ interface MailboxApi {
@Immutable
class PermanentFailureException extends Exception {
/**
* If true, the failure is fatal and requires user attention.
* The entire task queue will most likely need to stop.
*/
final boolean fatal;
PermanentFailureException(boolean fatal) {
this.fatal = fatal;
}
}
}

View File

@@ -42,25 +42,23 @@ class MailboxApiImpl implements MailboxApi {
.build();
OkHttpClient client = httpClientProvider.get();
Response response = client.newCall(request).execute();
if (response.code() == 401) {
throw new PermanentFailureException(true);
}
if (response.code() == 401) throw new PermanentFailureException();
if (!response.isSuccessful()) throw new IOException();
ResponseBody body = response.body();
if (body == null) throw new PermanentFailureException(false);
if (body == null) throw new PermanentFailureException();
try {
JsonNode node = mapper.readTree(body.string());
JsonNode tokenNode = node.get("token");
if (tokenNode == null) {
throw new PermanentFailureException(false);
throw new PermanentFailureException();
}
String ownerToken = tokenNode.textValue();
if (ownerToken == null) {
throw new PermanentFailureException(false);
throw new PermanentFailureException();
}
return ownerToken;
} catch (JacksonException e) {
throw new PermanentFailureException(false);
throw new PermanentFailureException();
}
}
@@ -73,9 +71,7 @@ class MailboxApiImpl implements MailboxApi {
.build();
OkHttpClient client = httpClientProvider.get();
Response response = client.newCall(request).execute();
if (response.code() == 401) {
throw new PermanentFailureException(true);
}
if (response.code() == 401) throw new PermanentFailureException();
return response.isSuccessful();
}

View File

@@ -65,27 +65,15 @@ public class MailboxApiTest extends BrambleTestCase {
assertEquals(token2, api.setup(properties));
PermanentFailureException e2 =
assertThrows(PermanentFailureException.class,
() -> api.setup(properties)
);
PermanentFailureException e3 =
assertThrows(PermanentFailureException.class,
() -> api.setup(properties)
);
PermanentFailureException e4 = assertThrows(
PermanentFailureException.class,
() -> api.setup(properties2)
);
assertThrows(PermanentFailureException.class,
() -> api.setup(properties));
assertThrows(PermanentFailureException.class,
() -> api.setup(properties));
assertThrows(PermanentFailureException.class,
() -> api.setup(properties2));
assertThrows(IOException.class,
() -> api.setup(properties)
);
PermanentFailureException e6 = assertThrows(
PermanentFailureException.class,
() -> api.setup(properties));
assertThrows(PermanentFailureException.class,
() -> api.setup(properties)
);
@@ -98,19 +86,16 @@ public class MailboxApiTest extends BrambleTestCase {
assertEquals("/setup", request2.getPath());
assertEquals("PUT", request2.getMethod());
assertToken(request2, token);
assertFalse(e2.fatal);
RecordedRequest request3 = server.takeRequest();
assertEquals("/setup", request3.getPath());
assertEquals("PUT", request3.getMethod());
assertToken(request3, token);
assertFalse(e3.fatal);
RecordedRequest request4 = server.takeRequest();
assertEquals("/setup", request4.getPath());
assertEquals("PUT", request4.getMethod());
assertToken(request4, token2);
assertTrue(e4.fatal);
RecordedRequest request5 = server.takeRequest();
assertEquals("/setup", request5.getPath());
@@ -121,7 +106,6 @@ public class MailboxApiTest extends BrambleTestCase {
assertEquals("/setup", request6.getPath());
assertEquals("PUT", request6.getMethod());
assertToken(request6, token);
assertFalse(e6.fatal);
}
@Test
@@ -149,9 +133,8 @@ public class MailboxApiTest extends BrambleTestCase {
assertTrue(api.checkStatus(properties));
PermanentFailureException e2 = assertThrows(
PermanentFailureException.class,
() -> api.checkStatus(properties2)
assertThrows(PermanentFailureException.class, () ->
api.checkStatus(properties2)
);
assertFalse(api.checkStatus(properties));
@@ -163,7 +146,6 @@ public class MailboxApiTest extends BrambleTestCase {
RecordedRequest request2 = server.takeRequest();
assertEquals("/status", request2.getPath());
assertToken(request2, token2);
assertTrue(e2.fatal);
RecordedRequest request3 = server.takeRequest();
assertEquals("/status", request3.getPath());