properly error out if upload fails. fixes #4052
(cherry picked from commit 202bde46ed8629442db3bd56596c5560270af508)
This commit is contained in:
parent
d43d2f7f9f
commit
dd8cde4600
1 changed files with 15 additions and 11 deletions
|
@ -46,7 +46,6 @@ public class HttpUploadConnection implements Transferable, AbstractConnectionMan
|
|||
private boolean delayed = false;
|
||||
private DownloadableFile file;
|
||||
private final Message message;
|
||||
private String mime;
|
||||
private SlotRequester.Slot slot;
|
||||
private byte[] key = null;
|
||||
private int mStatus = Transferable.STATUS_UNKNOWN;
|
||||
|
@ -89,11 +88,14 @@ public class HttpUploadConnection implements Transferable, AbstractConnectionMan
|
|||
public void cancel() {
|
||||
final ListenableFuture<SlotRequester.Slot> slotFuture = this.slotFuture;
|
||||
if (slotFuture != null && !slotFuture.isDone()) {
|
||||
slotFuture.cancel(true);
|
||||
if (slotFuture.cancel(true)) {
|
||||
Log.d(Config.LOGTAG,"cancelled slot requester");
|
||||
}
|
||||
}
|
||||
final Call call = this.mostRecentCall;
|
||||
if (call != null && !call.isCanceled()) {
|
||||
call.cancel();
|
||||
Log.d(Config.LOGTAG,"cancelled HTTP request");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -105,11 +107,6 @@ public class HttpUploadConnection implements Transferable, AbstractConnectionMan
|
|||
mXmppConnectionService.markMessage(message, Message.STATUS_SEND_FAILED, cancelled ? Message.ERROR_MESSAGE_CANCELLED : errorMessage);
|
||||
}
|
||||
|
||||
private void markAsCancelled() {
|
||||
finish();
|
||||
mXmppConnectionService.markMessage(message, Message.STATUS_SEND_FAILED, Message.ERROR_MESSAGE_CANCELLED);
|
||||
}
|
||||
|
||||
private void finish() {
|
||||
mHttpConnectionManager.finishUploadConnection(this);
|
||||
message.setTransferable(null);
|
||||
|
@ -118,10 +115,11 @@ public class HttpUploadConnection implements Transferable, AbstractConnectionMan
|
|||
public void init(boolean delay) {
|
||||
final Account account = message.getConversation().getAccount();
|
||||
this.file = mXmppConnectionService.getFileBackend().getFile(message, false);
|
||||
final String mime;
|
||||
if (message.getEncryption() == Message.ENCRYPTION_PGP || message.getEncryption() == Message.ENCRYPTION_DECRYPTED) {
|
||||
this.mime = "application/pgp-encrypted";
|
||||
mime = "application/pgp-encrypted";
|
||||
} else {
|
||||
this.mime = this.file.getMimeType();
|
||||
mime = this.file.getMimeType();
|
||||
}
|
||||
final long originalFileSize = file.getSize();
|
||||
this.delayed = delay;
|
||||
|
@ -142,7 +140,12 @@ public class HttpUploadConnection implements Transferable, AbstractConnectionMan
|
|||
FileTransferExecutor.execute(() -> {
|
||||
changeStatus(STATUS_UPLOADING);
|
||||
HttpUploadConnection.this.slot = result;
|
||||
HttpUploadConnection.this.upload();
|
||||
try {
|
||||
HttpUploadConnection.this.upload();
|
||||
} catch (final Exception e) {
|
||||
changeStatus(STATUS_FAILED);
|
||||
fail(e.getMessage());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -156,6 +159,7 @@ public class HttpUploadConnection implements Transferable, AbstractConnectionMan
|
|||
mXmppConnectionService.markMessage(message, Message.STATUS_UNSEND);
|
||||
}
|
||||
|
||||
|
||||
private void upload() {
|
||||
final OkHttpClient client = mHttpConnectionManager.buildHttpClient(
|
||||
slot.put,
|
||||
|
@ -178,7 +182,7 @@ public class HttpUploadConnection implements Transferable, AbstractConnectionMan
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException {
|
||||
public void onResponse(@NotNull Call call, @NotNull Response response) {
|
||||
final int code = response.code();
|
||||
if (code == 200 || code == 201) {
|
||||
Log.d(Config.LOGTAG, "finished uploading file");
|
||||
|
|
Loading…
Add table
Reference in a new issue