I\'d like to create my own error class in TypeScript, extending core Error
to provide better error handling and customized reporting. For example, I want to cre
There is a neat library for this at https://www.npmjs.com/package/ts-custom-error
ts-custom-error
allow you to create error custom Error very easily:
import { CustomError } from 'ts-custom-error'
class HttpError extends CustomError {
public constructor(
public code: number,
message?: string,
) {
super(message)
}
}
usage:
new HttpError(404, 'Not found')