@arndesk/attempt

1.0.0 • Public • Published

@arndesk/attempt

A simple utility to handle promises with optional logging and error throwing.

Get StartedInstallationUsageFeaturesContributingLicense

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.

Package Sidebar

Install

npm i @arndesk/attempt

Weekly Downloads

0

Version

1.0.0

License

MIT

Unpacked Size

3.85 kB

Total Files

4

Last publish

Collaborators

  • arndesk