fix(uploader, files/handlers): fix incorrect unlock, catch and check error after calling api (#26)

* fix(uploader, files/handlers): fix incorrect unlock, catch and check after calling api

* fix(uploader): fix uploader test
This commit is contained in:
Hexxa 2020-12-21 23:20:06 +08:00 committed by GitHub
parent 64493ec76a
commit cb26003b99
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 11 deletions

View file

@ -109,19 +109,36 @@ export class FileUploader {
} else {
this.errMsg = uploadResp.statusText;
this.chunkLen = Math.ceil(this.chunkLen * speedDownRatio);
const uploadStatusResp = await this.uploadStatus(this.filePath);
let uploadStatusResp: Response<UploadStatusResp> = undefined;
try {
uploadStatusResp = await this.uploadStatus(this.filePath);
} catch (e) {
if (uploadStatusResp == null) {
this.errMsg = `${this.errMsg}; unknown error: empty uploadStatus response`;
break;
} else if (uploadStatusResp.status === 500) {
if (
!uploadStatusResp.statusText.includes("fail to lock the file") &&
uploadStatusResp.statusText !== ""
) {
this.errMsg = `${this.errMsg}; unknown error: ${uploadStatusResp.statusText}`;
break;
}
} else if (uploadStatusResp.status === 600) {
this.errMsg = `${this.errMsg}; unknown error: ${uploadStatusResp.statusText}`;
break;
} else {
// ignore error and retry
}
}
if (uploadStatusResp.status === 200) {
this.offset = uploadStatusResp.data.uploaded;
} else if (uploadStatusResp.status === 600) {
this.errMsg = "unknown error";
break;
} else {
// do nothing and retry
}
}
if (this.progressCb != null) {
if (this.progressCb != null) {
this.progressCb(this.filePath, Math.ceil(this.offset / this.file.size));
}
}