Spaces:
Sleeping
Sleeping
| /** | |
| * Standardized application error class. | |
| * Always throw this instead of plain Error in route/service code | |
| * so the global error handler can format responses correctly. | |
| */ | |
| class ApiError extends Error { | |
| constructor(statusCode, message, errors = [], stack = '') { | |
| super(message); | |
| this.statusCode = statusCode; | |
| this.message = message; | |
| this.success = false; | |
| this.errors = errors; | |
| if (stack) { | |
| this.stack = stack; | |
| } else { | |
| Error.captureStackTrace(this, this.constructor); | |
| } | |
| } | |
| } | |
| module.exports = ApiError; | |