Browse Source

🐞 fix: 增加代理错误处理

Pchen0 8 hours ago
parent
commit
9ad6072b97
1 changed files with 8 additions and 3 deletions
  1. 8 3
      lib/Lepao/lepaoSchoolHttp.js

+ 8 - 3
lib/Lepao/lepaoSchoolHttp.js

@@ -72,6 +72,7 @@ function isQgProxyEligibleFailure(err) {
     if (!err) return false
     const status = err.response?.status
     if (status === 407) return true
+    if (status === 408) return true
     if (status === 502 || status === 503 || status === 504) return true
     if (
         err.code &&
@@ -139,11 +140,11 @@ async function logSchoolOutbound(logger, phase, url, axiosMerge, opts = {}) {
 async function postLepaoSchool(url, data, options = {}) {
     const { headers = {}, timeout = 15000, logger = null } = options
 
-    const doPost = async (qgProxyFragment) => {
+    const doPost = async (qgProxyFragment, requestTimeout = timeout) => {
         const outbound = buildAxiosOutboundConfig(qgProxyFragment)
         return axios.post(url, data, {
             headers,
-            timeout,
+            timeout: requestTimeout,
             ...outbound
         })
     }
@@ -192,7 +193,11 @@ async function postLepaoSchool(url, data, options = {}) {
 
     await logSchoolOutbound(logger, '首次请求', url, frag)
     try {
-        return await doPost(frag)
+        const proxyFirstTimeoutMs = Math.max(
+            1000,
+            Number(process.env.LEPAO_PROXY_FIRST_TIMEOUT_MS || Math.min(timeout, 6000))
+        )
+        return await doPost(frag, proxyFirstTimeoutMs)
     } catch (e1) {
         if (!isQgProxyEligibleFailure(e1)) throw e1
         logger?.warn?.(