'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;