fix service.js

This commit is contained in:
ERROR204
2025-06-29 03:06:31 +08:00
committed by GitHub
parent d1d80acef8
commit 3503e7d5b1

View File

@@ -60,7 +60,7 @@ app.use(
return proxyResData;
}
},
// 统一错误处理
// 统一错误处理(添加超时错误处理)
proxyErrorHandler: (err, res, next) => {
// 客户端断开连接的正常情况常见于SSE
if (err.code === 'ECONNRESET' || err.code === 'EPIPE') {
@@ -69,6 +69,15 @@ app.use(
return;
}
// 添加超时错误处理
if (err.code === 'ETIMEDOUT') {
console.log('Proxy request timed out:', err.code);
if (!res.headersSent) {
res.status(504).send('Gateway Timeout');
}
return;
}
// 其他错误正常处理
console.error('Proxy error:', err);
next(err);