0.1.2 • Published 5 years ago

timedout-promise-error v0.1.2

Weekly downloads
5
License
MIT
Repository
github
Last release
5 years ago

timedout-promise-error

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


Installation

yarn add timedout-promise-error
npm i timedout-promise-error --save

Usage

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)

// 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
}
0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago

0.0.9

5 years ago

0.0.8

5 years ago

0.0.7

5 years ago

0.0.6

5 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago