I want to cancel a file upload using abort Controller, but I’m founding errors.
My code:
var uploadAbortController = app.request.abortController();
app.request({
....
abortController: uploadAbortController,
});
$('.cancel').click(function(){
app.dialog.confirm('Are you sure you want to cancel?', function () {
uploadAbortController.abort();
})
});
When I click on cancel button (.cancel class), upload is cancelled, but I see the following error:
Uncaught (in promise) Error: canceled
at p.abortController.onAbort (request.js:197:16)
at Object.abort (request.js:397:40)
at Object.onClick (app.js:277:28)
at HTMLSpanElement.v (dialog-class.js:107:34)
at HTMLSpanElement.l (dom7.esm.js:377:14)
User can start upload routine again, so I need that abort Controller works again. So I fix it moving the uploadAbortController declaration to the block that runs when user starts the upload:
//User starts the upload. Code executes here
var uploadAbortController = app.request.abortController();
//Unbind click event eventually active
$('.cancel').off('click');
$('.cancel').click(function(){
app.dialog.confirm('Are you sure you want to cancel?', function () {
uploadAbortController.abort();
})
});
//Request
app.request({
....
abortController: uploadAbortController,
});