Actually throw TolerableFailureException when *deleting* a contact

Before, this was accidentally added to *listing* contacts.
This commit is contained in:
Torsten Grote
2022-01-07 14:29:14 -03:00
parent af3389e0e1
commit 9fa54bf15c
3 changed files with 20 additions and 20 deletions

View File

@@ -43,20 +43,20 @@ interface MailboxApi {
/**
* Deletes a contact from the mailbox.
* This should get called after a contact was removed from Briar.
*/
void deleteContact(MailboxProperties properties, ContactId contactId)
throws IOException, ApiException;
/**
* Gets a list of {@link ContactId}s from the mailbox.
* These are the contacts that the mailbox already knows about.
*
* @throws TolerableFailureException if response code is 404
* (contact probably was already deleted).
*/
Collection<ContactId> getContacts(MailboxProperties properties)
void deleteContact(MailboxProperties properties, ContactId contactId)
throws IOException, ApiException, TolerableFailureException;
/**
* Gets a list of {@link ContactId}s from the mailbox.
* These are the contacts that the mailbox already knows about.
*/
Collection<ContactId> getContacts(MailboxProperties properties)
throws IOException, ApiException;
@Immutable
@JsonSerialize
class MailboxContact {

View File

@@ -113,7 +113,7 @@ class MailboxApiImpl implements MailboxApi {
@Override
public void deleteContact(MailboxProperties properties, ContactId contactId)
throws IOException, ApiException {
throws IOException, ApiException, TolerableFailureException {
if (!properties.isOwner()) throw new IllegalArgumentException();
String url = properties.getOnionAddress() + "/contacts/" +
contactId.getInt();
@@ -123,15 +123,15 @@ class MailboxApiImpl implements MailboxApi {
.build();
OkHttpClient client = httpClientProvider.get();
Response response = client.newCall(request).execute();
if (response.code() == 404) throw new TolerableFailureException();
if (response.code() != 200) throw new ApiException();
}
@Override
public Collection<ContactId> getContacts(MailboxProperties properties)
throws IOException, ApiException, TolerableFailureException {
throws IOException, ApiException {
if (!properties.isOwner()) throw new IllegalArgumentException();
Response response = sendGetRequest(properties, "/contacts");
if (response.code() == 404) throw new TolerableFailureException();
if (response.code() != 200) throw new ApiException();
ResponseBody body = response.body();