fetch-with-status
fetch with status helpers.
A small lib so you remember to check the status code of your request.
Installation
npm install fetch-with-status
yarn add fetch-with-status
example
const withStatus =
Summary
API
when
Takes a number | array of numbers and a function.
What gets returned from executed .when get passed to original promise chain after execution.
Syntax
Parameters
- number || Array of numbers: desired status code:s
- function:
- params:
- response: fetch response object
- next: call
next()
if you want to continue to the standard .then promise chain
- returns: any
- params:
Return value
self so we can chain multible .when
Build
Syntax
Parameters
none
Return value
Promise: originl fetch promise
Usage
// Require it like thisconst withStatus = // Wrap your fetch with the `withStatus` function // then add all the status handlers you want // the full request object is returned in all handlers // after you added all your desired handlers call .build // now we have the original promise so we can add .then:s and a .catch
TODO:
- make stuff immutable (more fp)
- tests