add types for errors

This commit is contained in:
Elliot DeNolf
2020-11-23 22:43:35 -05:00
parent badd59ac38
commit 6fcf4ebc48
9 changed files with 22 additions and 8 deletions

View File

@@ -5,6 +5,14 @@ import httpStatus from 'http-status';
* @extends Error
*/
class ExtendableError extends Error {
status: number;
data: any;
isPublic: boolean;
isOperational: boolean;
constructor(message: string, status: number, data: any, isPublic: boolean) {
super(message);
this.name = this.constructor.name;
@@ -13,6 +21,8 @@ class ExtendableError extends Error {
this.data = data;
this.isPublic = isPublic;
this.isOperational = true; // This is required since bluebird 4 doesn't append it anymore.
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore Couldn't get the compiler to love me
Error.captureStackTrace(this, this.constructor.name);
}
}