Description
A zero-dependency JavaScript library for error handling. It is inspired by Go, and returns a tuple containing the error and the result instead of throwing an exception.
Unlike other JavaScript libraries (await-to-js), supports async/await, promises and regular functions.
Installation
npm i saferr
Examples
Async
;; const safeGet = ; const testAsync = async { const err result = await ; if err console; return; console;}; // prints: zdenka.dieckmann@example.com; // prints: Network Error;
Sync
; const syncFunc = { if shouldThrow throw "Oops..."; return "ok";}; const safeSyncFunc = ; const testSync = { const err result = ; if err console; return; console;}; // prints: ok; // prints: Oops...;