Edit this page

up.network up.network.abort([condition], [options])
JavaScript function

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.

Effects of aborting

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.

Aborting all requests

Without arguments, this will abort all pending requests:

up.network.abort()

Aborting a single request

To abort a given up.Request object, pass it as the first argument:

let request = up.request('/path')
up.network.abort(request)

Aborting requests matching a pattern

To abort all requests matching an URL pattern, pass it as the first argument:

up.network.abort('/path/*')

Aborting requests matching an arbitrary condition

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')

Aborting requests targeting a fragment or layer

Use up.fragment.abort().


Parameters

[condition=true] stringorFunction(up.Request): booleanorup.Requestorboolean optional

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.

[options.reason] string optional

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.

[options.except] up.Request optional experimental

An up.Request that should not be aborted even if it matches the given condition.