davidohlin / await-to-fetch

⏱ Easy error handling for async/await fetch requests without try/catch

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

await-to-fetch Build Status

Easy error handling for async/await without try/catch blocks that works with fetch.

Install

$ npm install await-to-fetch

Usage

import to from 'await-to-fetch'

async function example() {
  const [err, res] = await to(fetch('https://httpstat.us/200'))

  if (err) {
    throw err
  }

  return res
}

Credits

About

⏱ Easy error handling for async/await fetch requests without try/catch


Languages

Language:TypeScript 74.6%Language:JavaScript 25.4%