1.2.0 • Published 6 years ago

@robotmayo/coderr v1.2.0

Weekly downloads
2
License
MIT
Repository
-
Last release
6 years ago

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;