New:Socket for Asana Is Now Available.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 library

Source
npmnpm
Version
0.14.1
Version published
Weekly downloads
332
-56.66%
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 07 Nov 2022

Related posts