Aller au contenu principal

@w5s/error

W5S Error module (@w5s/error)

NPM Version License

Installation

npm install @w5s/error

Usage

import { CustomError, Error, TypeError } from '@w5s/error';

export interface MyError
extends CustomError<{
name: 'MyError';
foo: string;
bar: boolean;
}> {}
export const MyError = CustomError.define<MyError>({ errorName: 'MyError' });

const myError = MyError({
foo: 'this is foo',
bar: true,
cause: TypeError('this is the cause'),
});
console.log(myError instanceof Error); // true

License

MIT © Julien Polo julien.polo@gmail.com

Index

Constructor

CustomError

CustomError: CustomErrorConstructor

Return a new CustomError

@example
const parentError: Error;
const error = CustomError({
name: 'FooError' as const, // this is required
message: 'my custom message', // customize message (optional)
cause: parentError, // Error that caused this error (optional)
})
@param

initial properties

Other

CustomError

CustomError<Properties>: globalThis.Error & Readonly<{ cause: unknown; message: string; stack: string | undefined } & Properties>

A custom error type


Type parameters

  • Properties: { name: string }
Page Options