npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@nuov.io/error-handling

v1.1.59

Published

The @nuov.io error handling library.

Downloads

206

Readme

Error Handling

Description

Error Handling is a TypeScript module that provides a structured approach to error handling in applications and builds on top of @nuov.io/error-handler. It serves as the error handling layer for the @nuov.io ecosystem.

The ErrorHandling interface is designed for dependency injection. The ErrorHandlingService is an abstract singleton service that implements the ErrorHandler interface and simplifies creating application-wide error handling. The ThrowErrorHandler is a concrete ErrorHandler class that re-throws errors; it is a last resort in error handling.

Installation

npm install @nuov.io/error-handling

Usage

Extending ErrorHandlingService

ErrorHandlingService is an abstract singleton base class. Extend it to create a custom error handling service, initialize it once at application startup, and access the instance anywhere via the static instance getter.

import {
  type ErrorHandler,
  ErrorHandlingService,
} from "@nuov.io/error-handling";

class ExampleErrorHandlingService extends ErrorHandlingService<ExampleErrorHandlingService> {
  public static initialize(): void {
    const exampleErrorHandlingService: ExampleErrorHandlingService =
      new ExampleErrorHandlingService();
    exampleErrorHandlingService.initialize(exampleErrorHandlingService);
  }

  public override handleError(error: unknown): void {
    // Custom error handling logic here
  }
}

// Initialize once at startup
ExampleErrorHandlingService.initialize();

// Initializing more than once throws an error
ExampleErrorHandlingService.initialize();
// throws: "The property 'ErrorHandlingService.instance' is not undefined."

// Access the singleton
ErrorHandlingService.instance.handleError(new Error("Something went wrong."));

// Create local variable
const errorHandler: ErrorHandler = ErrorHandlingService.instance;

Using ThrowErrorHandler

ThrowErrorHandler is a concrete error handler that simply re-throws any error passed to it. It is useful as a default handler or in testing scenarios.

import { type ErrorHandler, ThrowErrorHandler } from "@nuov.io/error-handling";

const errorHandler: ErrorHandler = new ThrowErrorHandler();
errorHandler.handleError(new Error("This error will be re-thrown"));

Preferential error handling

This example demonstrates how to use this module to achieve preferential error handling:

import {
  type ErrorHandler,
  type ErrorHandling,
  ErrorHandlingService,
  ThrowErrorHandler,
} from "@nuov.io/error-handling";

class SomeService implements ErrorHandler {
  private readonly _errorHandler: ErrorHandler | undefined;

  public constructor(errorHandler?: ErrorHandler | ErrorHandling) {
    // this is intentionally verbose...

    // no ErrorHandler | ErrorHandling
    if (errorHandler === undefined) {
      this._errorHandler = undefined;
    }

    // ErrorHandling
    else if ("errorHandler" in errorHandler) {
      this._errorHandler = errorHandler.errorHandler;
    }

    // ErrorHandler
    else {
      this._errorHandler = errorHandler;
    }
  }

  public something(errorHandler?: ErrorHandler): void {
    try {
      // ...
      // code here
      // ...
    } catch (error: unknown) {
      // function level error handler
      if (errorHandler !== undefined) {
        errorHandler.handleError(error);
      } else {
        // defaults to class level error handler
        this.handleError(error);
      }
    }
  }

  public handleError(error: unknown): void {
    // class level error handler
    if (this._errorHandler !== undefined) {
      this._errorHandler.handleError(error);
    }

    // application level error handler
    else if (ErrorHandlingService.isInitialized) {
      ErrorHandlingService.instance.handleError(error);
    }

    // no error handler - last resort
    else {
      const throwErrorHandler: ErrorHandler = new ThrowErrorHandler();
      throwErrorHandler.handleError(error);
    }
  }
}

ErrorHandler and ErrorHandlerPrototype

This package also re-exports the ErrorHandler interface and the ErrorHandlerPrototype class from @nuov.io/error-handler for convenience.

import {
  type ErrorHandler,
  ErrorHandlerPrototype,
} from "@nuov.io/error-handling";

API Reference

ErrorHandling (interface)

A contract for classes that expose an error handler.

| Property | Type | Description | | ----------------------- | -------------- | --------------------------- | | readonly errorHandler | ErrorHandler | The error handler instance. |

ErrorHandlingService<T extends ErrorHandlingService<T>> (abstract class)

An abstract singleton base class that implements the ErrorHandler interface to simplify the creation of application-wide error handling services.

Static Properties

| Property | Type | Description | | --------------- | -------------- | ----------------------------------------------------------------------------------------------------------------------- | | instance | ErrorHandler | Returns the singleton instance. Throws "The property 'ErrorHandlingService.instance' is undefined." if not initialized. | | isInitialized | boolean | Returns true if the service has been initialized. |

Protected Methods

| Method | Returns | Description | | ------------------------------------- | ------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | initialize(errorHandlingService: T) | void | Sets the singleton instance and is designed to be used within a subclass initialize static method. Throws "The property 'ErrorHandlingService.instance' is not undefined." if already initialized by any subclass. |

Abstract Methods

| Method | Returns | Description | | ----------------------------- | ------- | ----------------------------------------------------- | | handleError(error: unknown) | void | Handles the error. Must be implemented by subclasses. |

ThrowErrorHandler (class)

A concrete error handler that re-throws any error passed to it. Extends ErrorHandlerPrototype.

Constructor

new ThrowErrorHandler();

Methods

| Method | Returns | Description | | ----------------------------- | ------- | ----------------------------- | | handleError(error: unknown) | void | Re-throws the provided error. |

License

MIT License