isAbortError

function isAbortError(err): err is Error;

Returns true if the given value is an Error whose name is 'AbortError'.

When an AbortSignal fires without a custom reason, or when APIs like fetch are aborted, they reject with a DOMException (or similar Error subclass) whose name is 'AbortError'. This helper lets callers distinguish abort rejections from other failures without having to instanceof-check every platform-specific error class.

Parameters

ParameterType
errunknown

Returns

err is Error

Example

try {
    await getAbortablePromise(doWork(), signal);
} catch (e) {
    if (isAbortError(e)) {
        // The operation was aborted; don't surface as an error.
        return;
    }
    throw e;
}

See

getAbortablePromise

On this page