2.0.0 • Published 2 years ago

@fatcherjs/middleware-aborter v2.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

@fatcherjs/middleware-aborter

A middleware for aborting fatcher request.

codecov install size

Install

NPM

>$ npm install @fatcherjs/middleware-aborter

CDN

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

Usage

import { aborter, isAbortError } from '@fatcherjs/middleware-aborter';
import { fatcher } from 'fatcher';

fatcher({
    url: '/bar/foo',
    middlewares: [
        aborter({
            timeout: 10 * 1000, // 10s
            onAbort: () => {
                console.log('Request is Aborted.');
            },
        }),
    ],
})
    .then(res => {
        // Request success in 10s
        console.log(res);
    })
    .catch(err => {
        if (isAbortError(err)) {
            //Run error when request aborted.
            console.error(err);
        }

        // Other errors.
    });

Options

NameDescriptionTypeDefaultValue
timeoutIf timeout > 0, will abort this request laternumber0
onAbortA callback when aborting this request(() => void) \| nullnull
concurrencyRequest concurrency restrictionsbooleanfalse
groupByConcurrency key(context: Readonly<Context>) => string${context.url}_${context.method}_${new URLSearchParams(context.params).toString()}

License

MIT

1.7.2

2 years ago

1.8.0

2 years ago

2.0.0

2 years ago

1.7.1

2 years ago

1.7.0

2 years ago

1.6.1

2 years ago

1.6.0

2 years ago

1.5.0

2 years ago

1.4.1

2 years ago

1.4.0

2 years ago

1.3.0

2 years ago

1.2.0

2 years ago

1.0.0

2 years ago