🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

@opvious/stl-errors

Package Overview
Dependencies
Maintainers
1
Versions
290
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@opvious/stl-errors

Standard errors

Source
npmnpm
Version
0.26.4
Version published
Weekly downloads
228
-41.98%
Maintainers
1
Weekly downloads
 
Created
Source

Standard errors

Motivation

Good error handling is a prerequisite for good telemetry. To help with this, @opvious/stl-errors provides a simple StandardError interface which exposes powerful building blocks:

  • Namespaced error codes;
  • Causal chains;
  • Optional structured data.

Quickstart

Standard errors are best created via errorFactories which provides type-safe error creation functions along with their codes:

import {errorFactories} from '@opvious/stl-errors';

const [errors, codes] = errorFactories({
  definitions: {
    invalidFoo: (foo: string) => ({
      message: `The input foo ${foo} was invalid`,
      tags: {foo},
    }),
    missingBar: 'The bar was missing',
  },
});

// Error with code `ERR_INVALID_FOO` (`codes.InvalidFoo`).
const err1 = errors.invalidFoo('fff');

// Error with code `ERR_MISSING_BAR` (`codes.MissingBar`).
const err2 = errors.missingBar();

Keywords

stl

FAQs

Package last updated on 21 Nov 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts