mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-01-14 06:07:23 +08:00
- Updated logging statements across various modules to provide more structured and detailed information. - Changed log levels from info to debug for less critical messages to reduce log clutter. - Enhanced error logging to include relevant context such as agentId, sessionId, and model details. - Standardized log messages to follow a consistent format, improving readability and maintainability.
22 lines
685 B
TypeScript
22 lines
685 B
TypeScript
import { NextFunction, Request, Response } from 'express'
|
|
|
|
import { loggerService } from '../../services/LoggerService'
|
|
|
|
const logger = loggerService.withContext('ApiServerErrorHandler')
|
|
|
|
// oxlint-disable-next-line @typescript-eslint/no-unused-vars
|
|
export const errorHandler = (err: Error, _req: Request, res: Response, _next: NextFunction) => {
|
|
logger.error('API server error', { error: err })
|
|
|
|
// Don't expose internal errors in production
|
|
const isDev = process.env.NODE_ENV === 'development'
|
|
|
|
res.status(500).json({
|
|
error: {
|
|
message: isDev ? err.message : 'Internal server error',
|
|
type: 'server_error',
|
|
...(isDev && { stack: err.stack })
|
|
}
|
|
})
|
|
}
|