Abort Controller not working

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)

Also abort not work on futures uploads

What’s wrong? Thanks

nothing wrong

AbortController is a one-time-use

not an error
just a normal output when ‘promise’ is rejected/canceled/aborted

if you dont want to see the stack trace,
then just add a catch + e.message

// request
let controller = app.request.abortController();

app.request({
  url: 'https://jsonplaceholder.typicode.com/todos/1',
  abortController: controller,
  dataType: 'json'
}).then(d => console.log(d.data))
.catch(e => console.log(e.message));

controller.abort();
// output => 'canceled'

// fetch
let controller = new AbortController();

fetch('https://jsonplaceholder.typicode.com/todos/1',{
  signal: controller.signal
}).then(r => r.json()).then(d => console.log(d))
.catch(e => console.log(e.message));

controller.abort();
// output => 'The user aborted a request.'

Oh, nice. So my main problem was…

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,
});

Now, the abort always work

Thanks for helping :slight_smile: