track upload error

This commit is contained in:
Bruno Windels 2020-11-11 11:51:11 +01:00
parent 91f15074be
commit 48cd4ac95d

View file

@ -29,6 +29,7 @@ export class AttachmentUpload {
this._uploadPromise = null; this._uploadPromise = null;
this._uploadRequest = null; this._uploadRequest = null;
this._aborted = false; this._aborted = false;
this._error = null;
} }
upload() { upload() {
@ -39,19 +40,28 @@ export class AttachmentUpload {
} }
async _upload() { async _upload() {
let transferredBlob = this._unencryptedBlob; try {
if (this.isEncrypted) { let transferredBlob = this._unencryptedBlob;
const {info, blob} = await encryptAttachment(this._platform, this._unencryptedBlob); if (this._isEncrypted) {
transferredBlob = blob; const {info, blob} = await encryptAttachment(this._platform, this._unencryptedBlob);
this._encryptionInfo = info; transferredBlob = blob;
this._encryptionInfo = info;
}
if (this._aborted) {
return;
}
this._uploadRequest = this._hsApi.uploadAttachment(transferredBlob, this._filename);
const {content_uri} = await this._uploadRequest.response();
this._mxcUrl = content_uri;
this._transferredBlob = transferredBlob;
} catch (err) {
this._error = err;
throw err;
} }
if (this._aborted) { }
return;
} get isUploaded() {
this._uploadRequest = this._hsApi.uploadAttachment(transferredBlob, this._filename); return !!this._transferredBlob;
const {content_uri} = await this._uploadRequest.response();
this._mxcUrl = content_uri;
this._transferredBlob = transferredBlob;
} }
/** @public */ /** @public */
@ -65,6 +75,10 @@ export class AttachmentUpload {
return this._unencryptedBlob; return this._unencryptedBlob;
} }
get error() {
return this._error;
}
/** @package */ /** @package */
uploaded() { uploaded() {
if (!this._uploadPromise) { if (!this._uploadPromise) {