Aborts pending requests.
The event up:request:aborted
will be emitted.
The promise returned by up.request()
will be rejected with an exception named AbortError
:
try {
let response = await up.request('/path')
console.log(response.text)
} catch (err) {
if (err.name == 'AbortError') {
console.log('Request was aborted')
}
}
Without arguments, this will abort all pending requests:
up.network.abort()
To abort a given up.Request
object, pass it as the first argument:
let request = up.request('/path')
up.network.abort(request)
To abort all requests matching a condition, pass a function that takes a request
and returns a boolean value. Unpoly will abort all request for which the given
function returns true
. E.g. to abort all requests with a HTTP method as GET
:
up.network.abort((request) => request.method == 'GET')
If this argument is omitted, all pending requests are aborted.