@robotmayo/coderr
TypeScript icon, indicating that this package has built-in type declarations

1.2.0 • Public • Published

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;

Readme

Keywords

Package Sidebar

Install

npm i @robotmayo/coderr

Weekly Downloads

0

Version

1.2.0

License

MIT

Last publish

Collaborators

  • robotmayo