From 9f1757ccaf4e0f0571cc3a957079a0a22e3a25c4 Mon Sep 17 00:00:00 2001 From: Torsten Grote Date: Wed, 15 Dec 2021 16:54:04 -0300 Subject: [PATCH] Remove concept of fatal permanent exceptions All exceptions will just cause the request to be tried again with some backoff. --- .../bramble/mailbox/MailboxApi.java | 9 ----- .../bramble/mailbox/MailboxApiImpl.java | 16 +++----- .../bramble/mailbox/MailboxApiTest.java | 38 +++++-------------- 3 files changed, 16 insertions(+), 47 deletions(-) diff --git a/bramble-core/src/main/java/org/briarproject/bramble/mailbox/MailboxApi.java b/bramble-core/src/main/java/org/briarproject/bramble/mailbox/MailboxApi.java index 77add349d..97539bd84 100644 --- a/bramble-core/src/main/java/org/briarproject/bramble/mailbox/MailboxApi.java +++ b/bramble-core/src/main/java/org/briarproject/bramble/mailbox/MailboxApi.java @@ -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; - } } } diff --git a/bramble-core/src/main/java/org/briarproject/bramble/mailbox/MailboxApiImpl.java b/bramble-core/src/main/java/org/briarproject/bramble/mailbox/MailboxApiImpl.java index 30c52212d..df35d5723 100644 --- a/bramble-core/src/main/java/org/briarproject/bramble/mailbox/MailboxApiImpl.java +++ b/bramble-core/src/main/java/org/briarproject/bramble/mailbox/MailboxApiImpl.java @@ -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(); } diff --git a/bramble-core/src/test/java/org/briarproject/bramble/mailbox/MailboxApiTest.java b/bramble-core/src/test/java/org/briarproject/bramble/mailbox/MailboxApiTest.java index 374d99eec..42054f5fc 100644 --- a/bramble-core/src/test/java/org/briarproject/bramble/mailbox/MailboxApiTest.java +++ b/bramble-core/src/test/java/org/briarproject/bramble/mailbox/MailboxApiTest.java @@ -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());