import { Request, Response, NextFunction } from 'express';
import { createLogger } from '../utils/logger';

const logger = createLogger('errorHandler');

export function errorHandler(err: Error, req: Request, res: Response, next: NextFunction) {
  logger.error('🔥 Server Error:', err.stack); // Logs the full stack trace
  if (!res.headersSent) {
    res.status(500).json({ error: 'Internal Server Error' });
  }
  next(err);
}
