# timedout-promise-error

> add a timeout on a promise with a configurable timeout error

Latest version **0.1.2** (published 2019-04-02) · MIT license · 0 weekly downloads

## Install

```sh
npm install timedout-promise-error
pnpm add timedout-promise-error
yarn add timedout-promise-error
bun add timedout-promise-error
```

## Health

**Score 25/100 (F)** — status: abandoned.

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

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.2 |
| Published | 2019-04-02 |
| First published | 2019-02-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 3.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | timbielawski |
| Maintainers | timbielawski |

## Links

- npm: https://www.npmjs.com/package/timedout-promise-error
- Repository: https://github.com/timbielawski/timedout-promise
- Homepage: https://github.com/timbielawski/timedout-promise#readme
- Issues: https://github.com/timbielawski/timedout-promise/issues
- npm.io page: https://npm.io/package/timedout-promise-error

## Recent versions

- 0.1.2 (latest) — 2019-04-02
- 0.1.1 — 2019-04-02
- 0.1.0 — 2019-02-21
- 0.0.9 — 2019-02-21
- 0.0.8 — 2019-02-20
- 0.0.7 — 2019-02-20
- 0.0.6 — 2019-02-20
- 0.0.5 — 2019-02-19
- 0.0.4 — 2019-02-19
- 0.0.3 — 2019-02-19
- 0.0.2 — 2019-02-19
- 0.0.1 — 2019-02-19

## README

# timedout-promise-error

An easy way to put a timeout on a promise with a custom error

* * *

## Installation

```sh
yarn add timedout-promise-error
```

```sh
npm i timedout-promise-error --save
```

* * *

## Usage

```js
import timedoutPromiseError from "timedout-promise-error"

// simple GET request:
try {
    const response = await timedoutPromiseError(fetch('https://www.somewhere.com'), 5000, {
      status: 504,  url: 'https://www.somewhere.com'
    });
} catch (error) {
    console.log(error.url); //https://www.somewhere.com
    console.log(error.status); //504
    console.log(error.stack); // Error.stack
}

```

* * *

## API
timedout-promise-error allows you to put a timeout on a promise while providing a custom error for the timeout. 
Your error is returned in a Error so you get the error stack too.
If the passed in promise has an error, it functions as expected

### `timedoutPromiseError(somePromise: Object, timeout: Number, error: Object)`

```js
// simple GET request:
try {
    const response = await timedoutPromiseError(fetch('https://www.somewhere.com'), 5000, {
      status: 504, url: 'https://www.somewhere.com'
    });
} catch (error) {
    console.log(error.url); //https://www.somewhere.com
    console.log(error.status); //504
    console.log(error.stack); // Error.stack
}

```

---
_Source: https://npm.io/package/timedout-promise-error · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
