Skip to content

Instantly share code, notes, and snippets.

View egargan-ft's full-sized avatar

Ed Gargan egargan-ft

View GitHub Profile
@egargan-ft
egargan-ft / better-error.ts
Created April 8, 2023 21:02
Snippers for better error handling in Typescript
/**
* Base error class that all application errors should extend.
*
* Like the native `Error`, but ensures subclasses are properly initialised and correctly typed.
*/
export class BaseError extends Error {
constructor(message: string) {
super(message);
Object.defineProperty(this, "name", { value: new.target.name });
Object.setPrototypeOf(this, new.target.prototype);