Skip to content

Commit 7e206dc

Browse files
committed
feat(tpl): show upload error on server error
1 parent f7ba509 commit 7e206dc

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

src/tpl/frontend/index.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -824,10 +824,16 @@
824824
if (elFailedMessage) {
825825
elFailedMessage.textContent = " - " + e.type;
826826
}
827+
batches.length = 0;
827828
}
828829

829830
function onLoad() {
830-
!uploading && location.reload();
831+
var status = this.status;
832+
if (status >= 200 && status <= 299) {
833+
!uploading && location.reload();
834+
} else {
835+
onFail({type: this.statusText || this.status});
836+
}
831837
}
832838

833839
function onProgress(e) {
@@ -846,6 +852,7 @@
846852
batches.push(files);
847853
} else {
848854
uploading = true;
855+
removeClass(elUploadStatus, classFailed);
849856
addClass(elUploadStatus, classUploading);
850857
uploadBatch(files);
851858
}
@@ -871,13 +878,13 @@
871878
});
872879

873880
var xhr = new XMLHttpRequest();
874-
xhr.upload.addEventListener('error', onComplete);
875-
xhr.upload.addEventListener('error', onFail);
876-
xhr.upload.addEventListener('abort', onComplete);
877-
xhr.upload.addEventListener('abort', onFail);
878-
xhr.upload.addEventListener('load', onComplete);
879-
xhr.upload.addEventListener('load', onSuccess);
880-
xhr.upload.addEventListener('load', onLoad);
881+
xhr.addEventListener('error', onComplete);
882+
xhr.addEventListener('error', onFail);
883+
xhr.addEventListener('abort', onComplete);
884+
xhr.addEventListener('abort', onFail);
885+
xhr.addEventListener('load', onComplete);
886+
xhr.addEventListener('load', onSuccess);
887+
xhr.addEventListener('load', onLoad);
881888
if (elProgress) {
882889
xhr.upload.addEventListener('progress', onProgress);
883890
}

0 commit comments

Comments
 (0)