Skip to content

safely catch errors from promises or functions, asynchronously or synchronously

License

Notifications You must be signed in to change notification settings

nomisaur/safely

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

safely

npm (scoped)

errors bad. catch errors. safely makes everything safe.

Install

$ npm install @emberscodes/safely

Usage

safely doesnt need to be awaited for syncronous functions:

// pass safely a syncronous function!
const [result, error] = safely(() => {
  throw "bonk";
});
// result === undefined
// error === 'bonk'

safely can handle async functions too:

// pass an asyncronous function and safely await it!!
const [result, error] = await safely(async () => {
  throw "bonk";
});
// result === undefined
// error === 'bonk'

safely can also take promises:

const bonkPromise = fetch("bonk.com");

// pass a promise and safely await that too!!!
const [result, error] = await safely(bonkPromise);
// result === 'you have been bonked'
// error === undefined

safely is very useful:

const [[bonkResult, bonkError], [images, imagesError]] = await Promise.all([
  safely(fetch("bonk.com")),
  safely(fetch("bonk.com/images")),
]);

pass anything to safely:

const [res, err] = safely("anything");
// res === 'anything'

Propoganda

Safely is very safe. Safely handles anything. You can pass anything to safely. Wrap everything in safely. Safely will fix you code. Safely will cure your depression.

About

safely catch errors from promises or functions, asynchronously or synchronously

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published