Make deleting a non-existent file is tolerable

This commit is contained in:
Torsten Grote
2022-01-21 15:04:51 -03:00
parent 0fba65a722
commit 61ea7ff8de
4 changed files with 22 additions and 2 deletions

View File

@@ -92,9 +92,13 @@ interface MailboxApi {
* Used by owner and contacts to delete files.
* <p>
* Returns 200 OK (no exception) if deletion was successful.
*
* @throws TolerableFailureException on 404 response,
* because file was most likely deleted already.
*/
void deleteFile(MailboxProperties properties, String folderId,
String fileId) throws IOException, ApiException;
String fileId)
throws IOException, ApiException, TolerableFailureException;
/**
* Lists all contact outboxes that have files available

View File

@@ -223,7 +223,8 @@ class MailboxApiImpl implements MailboxApi {
@Override
public void deleteFile(MailboxProperties properties, String folderId,
String fileId) throws IOException, ApiException {
String fileId)
throws IOException, ApiException, TolerableFailureException {
String path = "/files/" + folderId + "/" + fileId;
Request request = getRequestBuilder(properties.getAuthToken())
.delete()
@@ -231,6 +232,7 @@ 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();
}