properly error out if upload fails. fixes #4052
This commit is contained in:
parent
37ce311764
commit
202bde46ed
|
@ -44,7 +44,6 @@ public class HttpUploadConnection implements Transferable, AbstractConnectionMan
|
||||||
private boolean delayed = false;
|
private boolean delayed = false;
|
||||||
private DownloadableFile file;
|
private DownloadableFile file;
|
||||||
private final Message message;
|
private final Message message;
|
||||||
private String mime;
|
|
||||||
private SlotRequester.Slot slot;
|
private SlotRequester.Slot slot;
|
||||||
private byte[] key = null;
|
private byte[] key = null;
|
||||||
|
|
||||||
|
@ -86,11 +85,14 @@ public class HttpUploadConnection implements Transferable, AbstractConnectionMan
|
||||||
public void cancel() {
|
public void cancel() {
|
||||||
final ListenableFuture<SlotRequester.Slot> slotFuture = this.slotFuture;
|
final ListenableFuture<SlotRequester.Slot> slotFuture = this.slotFuture;
|
||||||
if (slotFuture != null && !slotFuture.isDone()) {
|
if (slotFuture != null && !slotFuture.isDone()) {
|
||||||
slotFuture.cancel(true);
|
if (slotFuture.cancel(true)) {
|
||||||
|
Log.d(Config.LOGTAG,"cancelled slot requester");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
final Call call = this.mostRecentCall;
|
final Call call = this.mostRecentCall;
|
||||||
if (call != null && !call.isCanceled()) {
|
if (call != null && !call.isCanceled()) {
|
||||||
call.cancel();
|
call.cancel();
|
||||||
|
Log.d(Config.LOGTAG,"cancelled HTTP request");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,11 +104,6 @@ public class HttpUploadConnection implements Transferable, AbstractConnectionMan
|
||||||
mXmppConnectionService.markMessage(message, Message.STATUS_SEND_FAILED, cancelled ? Message.ERROR_MESSAGE_CANCELLED : errorMessage);
|
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() {
|
private void finish() {
|
||||||
mHttpConnectionManager.finishUploadConnection(this);
|
mHttpConnectionManager.finishUploadConnection(this);
|
||||||
message.setTransferable(null);
|
message.setTransferable(null);
|
||||||
|
@ -115,10 +112,11 @@ public class HttpUploadConnection implements Transferable, AbstractConnectionMan
|
||||||
public void init(boolean delay) {
|
public void init(boolean delay) {
|
||||||
final Account account = message.getConversation().getAccount();
|
final Account account = message.getConversation().getAccount();
|
||||||
this.file = mXmppConnectionService.getFileBackend().getFile(message, false);
|
this.file = mXmppConnectionService.getFileBackend().getFile(message, false);
|
||||||
|
final String mime;
|
||||||
if (message.getEncryption() == Message.ENCRYPTION_PGP || message.getEncryption() == Message.ENCRYPTION_DECRYPTED) {
|
if (message.getEncryption() == Message.ENCRYPTION_PGP || message.getEncryption() == Message.ENCRYPTION_DECRYPTED) {
|
||||||
this.mime = "application/pgp-encrypted";
|
mime = "application/pgp-encrypted";
|
||||||
} else {
|
} else {
|
||||||
this.mime = this.file.getMimeType();
|
mime = this.file.getMimeType();
|
||||||
}
|
}
|
||||||
final long originalFileSize = file.getSize();
|
final long originalFileSize = file.getSize();
|
||||||
this.delayed = delay;
|
this.delayed = delay;
|
||||||
|
@ -136,7 +134,11 @@ public class HttpUploadConnection implements Transferable, AbstractConnectionMan
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(@NullableDecl SlotRequester.Slot result) {
|
public void onSuccess(@NullableDecl SlotRequester.Slot result) {
|
||||||
HttpUploadConnection.this.slot = result;
|
HttpUploadConnection.this.slot = result;
|
||||||
HttpUploadConnection.this.upload();
|
try {
|
||||||
|
HttpUploadConnection.this.upload();
|
||||||
|
} catch (final Exception e) {
|
||||||
|
fail(e.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -171,7 +173,7 @@ public class HttpUploadConnection implements Transferable, AbstractConnectionMan
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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();
|
final int code = response.code();
|
||||||
if (code == 200 || code == 201) {
|
if (code == 200 || code == 201) {
|
||||||
Log.d(Config.LOGTAG, "finished uploading file");
|
Log.d(Config.LOGTAG, "finished uploading file");
|
||||||
|
|
Loading…
Reference in a new issue