/await-to-fetch

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

Primary LanguageTypeScript

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