mirror of
https://github.com/Unleash/unleash.git
synced 2024-11-01 19:07:38 +01:00
a50d0e2a21
Unleash is an API and it would simplyfy a lot of the specific errors could carry the expected HTTP status code for this error. This would eliminate the need for a gigantic switch/case in the handle-errors function.
27 lines
583 B
TypeScript
27 lines
583 B
TypeScript
class BaseError extends Error {
|
|
readonly statusCode: number;
|
|
|
|
constructor(message: string, statusCode: number, name: string) {
|
|
super();
|
|
|
|
this.name = name;
|
|
this.message = message;
|
|
this.statusCode = statusCode;
|
|
Error.captureStackTrace(this, this.constructor);
|
|
}
|
|
|
|
toJSON(): object {
|
|
return {
|
|
isJoi: true,
|
|
name: this.constructor.name,
|
|
details: [
|
|
{
|
|
message: this.message,
|
|
},
|
|
],
|
|
};
|
|
}
|
|
}
|
|
|
|
export default BaseError;
|