<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/@fat
npm install @fatcherjs/middleware-aborterIf 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();
`
`bash`
>$ npm install @fatcherjs/middleware-aborter
`html
`
#### 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!');
},
});
`
`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
});
``