# @fatcherjs/middleware-aborter

Latest version **3.0.0** (published 2026-01-09) · 0 weekly downloads

## Install

```sh
npm install @fatcherjs/middleware-aborter
pnpm add @fatcherjs/middleware-aborter
yarn add @fatcherjs/middleware-aborter
bun add @fatcherjs/middleware-aborter
```

## Health

**Score 60/100 (C)** — status: stable.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 3.0.0 |
| Published | 2026-01-09 |
| First published | 2022-04-17 |
| Weekly downloads | 0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 9.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | fanhaoyuan |

## Links

- npm: https://www.npmjs.com/package/@fatcherjs/middleware-aborter
- Repository: https://github.com/fatcherjs/middleware-aborter
- Issues: https://github.com/fatcherjs/middleware-aborter/issues
- npm.io page: https://npm.io/package/@fatcherjs/middleware-aborter

## Recent versions

- 3.0.0 (latest) — 2026-01-09
- 3.0.0-alpha-11 — 2025-09-09
- 3.0.0-alpha-10 — 2024-11-01
- 3.0.0-alpha-9 — 2024-10-31
- 3.0.0-alpha-8 — 2024-10-30
- 3.0.0-alpha-7 — 2024-10-28
- 3.0.0-alpha-6 — 2024-10-27
- 3.0.0-alpha-5 — 2024-10-25
- 3.0.0-alpha-4 — 2024-10-25
- 2.0.0 — 2022-10-19
- 1.8.0 — 2022-09-18
- 1.7.2 — 2022-09-04
- 1.7.1 — 2022-08-20
- 1.7.0 — 2022-08-05
- 1.6.1 — 2022-07-30
- … 7 more at https://npm.io/package/@fatcherjs/middleware-aborter/versions

## README

# @fatcherjs/middleware-aborter

<div align="center">
  <a href="https://codecov.io/github/fatcherjs/middleware-aborter" > 
    <img src="https://codecov.io/github/fatcherjs/middleware-aborter/graph/badge.svg?token=BEJA311FY2"/> 
 </a>
  <a href="https://www.jsdelivr.com/package/npm/@fatcherjs/middleware-aborter">
    <img src="https://data.jsdelivr.com/v1/package/npm/@fatcherjs/middleware-aborter/badge?style=rounded" alt="jsDelivr">
  </a>
  <a href="https://packagephobia.com/result?p=@fatcherjs/middleware-aborter">
    <img src="https://packagephobia.com/badge?p=@fatcherjs/middleware-aborter" alt="install size">
  </a>
  <a href="https://unpkg.com/@fatcherjs/middleware-aborter">
    <img src="https://img.badgesize.io/https://unpkg.com/@fatcherjs/middleware-aborter" alt="Size">
  </a>
  <a href="https://npmjs.com/package/@fatcherjs/middleware-aborter">
    <img src="https://img.shields.io/npm/v/@fatcherjs/middleware-aborter.svg" alt="npm package">
  </a>
  <a href="https://github.com/fatcherjs/middleware-aborter/actions/workflows/ci.yml">
    <img src="https://github.com/fatcherjs/middleware-aborter/actions/workflows/ci.yml/badge.svg?branch=master" alt="build status">
  </a>
</div>

## Tips

If you want to abort request manually, you should use `AbortController` and pass the signal to `fatcher`

```ts
import { fatcher } from 'fatcher';

const abortController = new AbortController();

fatcher('your-url', {
  signal: abortController.signal,
}).catch(error => {
  if (error instanceof DOMException && error.name === 'AbortError') {
    // aborted.
    return;
  }

  // other
});

abortController.abort();
```

## Install

### NPM

```bash
>$ npm install @fatcherjs/middleware-aborter
```

### CDN

```html
<script src="https://cdn.jsdelivr.net/npm/fatcher/dist/fatcher.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@fatcherjs/middleware-aborter/dist/index.min.js"></script>

<script>
  Fatcher.fatcher('xxx', {
    middlewares: [FatcherMiddlewareAborter.timeout],
    onTimeout: () => {},
    timeout: 30000,
  })
    .then(response => {
      console.log(response);
    })
    .catch(error => {
      if (FatcherMiddlewareAborter.isTimeoutError(error)) {
        // do somethings
        return;
      }

      // do other thing
    });
</script>
```

## Usage

### Timeout

#### Types

```ts
declare module 'fatcher' {
  interface FatcherOptions {
    timeout?: number; // default 60 * 1000 (60s)
    onTimeout?: () => void;
  }
}
```

#### Basic

```ts
import { fatcher } from 'fatcher';
import { timeout } from '@fatcherjs/middleware-aborter';

const response = await fatcher('xxx', {
  middlewares: [timeout],
  timeout: 30 * 1000,
  onTimeout: () => {
    console.log('timeout!');
  },
});
```

### isTimeoutError

```ts
import { fatcher } from 'fatcher';
import { isTimeoutError, timeout } from '@fatcherjs/middleware-aborter';

fatcher('https://foo.bar', {
  timeout: 30 * 1000,
  middlewares: [timeout],
}).catch(error => {
  if (isTimeoutError(error)) {
    // do something..
    return;
  }
  // other error
});
```

## License

[MIT](https://github.com/fatcherjs/middleware-aborter/blob/master/LICENSE)

---
_Source: https://npm.io/package/@fatcherjs/middleware-aborter · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
