/
smaker21
/
YouTube-transcript-using-supadata
Обзор
Документация
Войти
/
smaker21
/
YouTube-transcript-using-supadata
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
backend/src/middlewares/errorHandler.ts
29 строк
849 B
Ilya Ostapov
new file: .env.example
12 фев 2026, 18:43
12 фев 2026, 18:43
7016baa
Код
Авторство
О чём код?
import type { Request, Response, NextFunction } from 'express'; import type { AppError } from '../types/index.js'; export function errorHandler( err: AppError, _req: Request, res: Response, _next: NextFunction ): void { const statusCode = err.statusCode || err.response?.status || 500; const message = err.message || 'Internal Server Error'; // Log error details (in production, use proper logging) console.error(JSON.stringify({ timestamp: new Date().toISOString(), statusCode, message, stack: process.env.NODE_ENV === 'development' ? err.stack : undefined, })); // Don't expose internal errors in production const responseMessage = statusCode === 500 && process.env.NODE_ENV === 'production' ? 'Internal Server Error' : message; res.status(statusCode).json({ error: responseMessage, }); }