Skip to content

Commit c2080ef

Browse files
committed
feat: permanent errors for chunk test requests
#35
1 parent ea3619a commit c2080ef

2 files changed

Lines changed: 33 additions & 6 deletions

File tree

src/flow.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,11 +1153,16 @@
11531153
*/
11541154
this.testHandler = function(event) {
11551155
var status = $.status();
1156-
if (status === 'success') {
1156+
if (status === 'error') {
1157+
$.event(status, $.message());
1158+
$.flowObj.uploadNextChunk();
1159+
} else if (status === 'success') {
11571160
$.tested = true;
1158-
$.fileObj.chunkEvent(status, $.message());
1161+
$.event(status, $.message());
11591162
$.flowObj.uploadNextChunk();
1160-
} else if (!$.fileObj.paused) {// Error might be caused by file pause method
1163+
} else if (!$.fileObj.paused) {
1164+
// Error might be caused by file pause method
1165+
// Chunks does not exist on the server side
11611166
$.tested = true;
11621167
$.send();
11631168
}
@@ -1321,7 +1326,7 @@
13211326
// HTTP 202 Accepted - The request has been accepted for processing, but the processing has not been completed.
13221327
return 'success';
13231328
} else if (this.flowObj.opts.permanentErrors.indexOf(this.xhr.status) > -1 ||
1324-
this.retries >= this.flowObj.opts.maxChunkRetries) {
1329+
this.retries && this.retries >= this.flowObj.opts.maxChunkRetries) {
13251330
// HTTP 415/500/501, permanent error
13261331
return 'error';
13271332
} else {

test/uploadSpec.js

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,30 @@ describe('upload file', function() {
331331
expect(success).not.toHaveBeenCalled();
332332
});
333333

334+
it('should fail on permanent test error', function () {
335+
flow.opts.testChunks = true;
336+
flow.opts.chunkSize = 1;
337+
flow.opts.simultaneousUploads = 2;
338+
flow.opts.maxChunkRetries = 1;
339+
flow.opts.permanentErrors = [500];
340+
341+
var error = jasmine.createSpy('error');
342+
var success = jasmine.createSpy('success');
343+
var retry = jasmine.createSpy('retry');
344+
flow.on('fileError', error);
345+
flow.on('fileSuccess', success);
346+
flow.on('fileRetry', retry);
347+
348+
flow.addFile(new Blob(['abc']));
349+
flow.upload();
350+
expect(requests.length).toBe(2);
351+
requests[0].respond(500);
352+
expect(requests.length).toBe(2);
353+
expect(error).toHaveBeenCalled();
354+
expect(retry).not.toHaveBeenCalled();
355+
expect(success).not.toHaveBeenCalled();
356+
});
357+
334358
it('should upload empty file', function () {
335359
var error = jasmine.createSpy('error');
336360
var success = jasmine.createSpy('success');
@@ -390,8 +414,6 @@ describe('upload file', function() {
390414
expect(error).not.toHaveBeenCalled();
391415
});
392416

393-
394-
395417
it('should preprocess chunks and wait for preprocess to finish', function () {
396418
flow.opts.simultaneousUploads = 1;
397419
var preprocess = jasmine.createSpy('preprocess');

0 commit comments

Comments
 (0)