r/javascript • • Sep 01 '25

Stop writing try/catch around fetch — I built safe-fetch (tiny, 0 deps, ~3kb)

https://github.com/asouei/safe-fetch

I was tired of wrapping every fetch in try/catch and guessing if the error is network, timeout or HTTP. So I made safe-fetch:

  • no throws, always returns { ok: true | false }

  • normalized errors (Network, Timeout, Http, Validation)

  • dual timeouts + smart retries

  • ~3kb, zero dependencies

1 Upvotes

9 comments sorted by

3

u/polaroid_kidd Sep 05 '25

what was your inspiration for building this and not using something like ky (179 kB (unpacked))

3

u/ranisalt Sep 05 '25

Probably to avoid the extra 176 KB

18

u/[deleted] Sep 02 '25

[removed] — view removed comment

12

u/Ecstatic_Ad_6153 Sep 02 '25

Yep, it’s still there — but hidden away, normalized, and wrapped with retries, timeouts and typed errors. Like how you don’t hand-write TCP packets even though HTTP is just wrapping them.

5

u/Byamarro Sep 05 '25

He wrote them for you so that you don't have to. That's called abstraction.