@arndesk/attempt
A simple utility to handle promises with optional logging and error throwing.
Get Started • Installation • Usage • Features • Contributing • License
Get Started
Installation
Use npm
to install this package:
npm install @arndesk/attempt
Usage
Here's a basic example of how to use @arndesk/attempt in your code:
const attempt = require('@arndesk/attempt');
async function demo() {
let result;
// Testing successful promise
result = await attempt(Promise.resolve("All good"), "Testing success");
console.log(result);
// Testing rejected promise without throwing the error
result = await attempt(Promise.reject(new Error("Oops")), "Testing failure");
console.log(result);
}
demo();
Features
- Handles promises with optional logging based on the provided description.
- Can either throw or return errors based on a flag.
- Useful for standardized error handling in asynchronous operations.