Aborts pending requests matching a condition.
Important
This is a low-level API matching requests by their properties. If possible, use
up.fragment.abort()
, which matches requests by screen region. Only when requests are aborted by screen region, components can react to being aborted.
When an up.request()
is aborted, its returned promise rejects with an up.AbortError
:
try {
let response = await up.request('/path')
console.log(response.text)
} catch (error) {
if (error instanceof up.AbortError) {
console.log('Request was aborted: ' + error.reason)
}
}
Also the event up:request:aborted
will be emitted.
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 an URL pattern, pass it as the first argument:
up.network.abort('/path/*')
To abort all requests matching an arbitrary 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')
Use up.fragment.abort()
.
A condition that controls which requests to abort.
If set to a string, it is interpreted as a URL pattern. All requests matching that pattern will be aborted.
If set to an up.Request
object, that one request is aborted.
If set to a function, it will be called for each pending requests.
All requests for which the function returns true
will be aborted.
If set to true
, all pending requests are aborted.
A reason for why the request was aborted.
If omitted, a generic reason like "Aborted request to GET /path"
will be used.
The reason will be set as the up.AbortError
's message.
An up.Request
that should not be aborted even if it matches the given condition
.