Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@robotmayo/coderr

robotmayo3MIT1.2.0TypeScript support: included

Produce errors with a code property.

error, code

readme

Coderr

A small extension on errors that adds a code property

npm i @robotmayo/coderr

Usage

import Coderr from "@robotmayo/coderr";

function throwable() {
  throw new Coderr("Hi I have a code", "ERR_EXAMPLE");
}

try {
  throwable();
} catch (err) {
  console.log(err.code);
}

You can also wrap existing errors

import { wrap } from "@robotmayo/coderr";

function throwable() {
  throw wrap(new Error("My Error"), "ERR_EXAMPLE");
}

try {
  throwable();
} catch (err) {
  console.log(err.code);
}

API

export default class Coderr extends Error {
  code: string;
  constructor(message?: string, code?: string);
}
export declare function wrap(e: Error, code?: string): Coderr;