26 lines
576 B
JavaScript
26 lines
576 B
JavaScript
'use strict';
|
|
|
|
/**
|
|
* Base application error class.
|
|
* All custom errors should extend this class.
|
|
*/
|
|
class AppError extends Error {
|
|
constructor(message, statusCode = 500, code = 'INTERNAL_ERROR') {
|
|
super(message);
|
|
this.name = this.constructor.name;
|
|
this.statusCode = statusCode;
|
|
this.code = code;
|
|
this.isOperational = true;
|
|
|
|
Error.captureStackTrace(this, this.constructor);
|
|
}
|
|
|
|
toJSON() {
|
|
return {
|
|
error: this.message,
|
|
code: this.code,
|
|
};
|
|
}
|
|
}
|
|
|
|
module.exports = AppError;
|