Преглед изворни кода

fix: preserve upstream login capacity conflicts

gangvy пре 3 недеља
родитељ
комит
cdbcceb1b9

+ 4 - 1
mcp/src/providers/fmode-wecom-gateway.js

@@ -176,7 +176,10 @@ async function callFmodeWecomGateway({
     const kind = classifyError({ httpStatus: response.status, code, message });
     const err = new Error(publicErrorMessage(kind));
     err.kind = kind;
-    err.httpStatus = code || response.status;
+    // The gateway may expose an upstream business code (for example 500) in a
+    // non-2xx response body. Preserve the actual HTTP status for callers so a
+    // recoverable 409 capacity conflict is not displayed as a generic 502.
+    err.httpStatus = response.status;
     err.bizCode = code;
     err.bizMessage = message;
     throw err;

+ 34 - 0
scripts/gateway-status-preservation-smoke-test.js

@@ -0,0 +1,34 @@
+const assert = require('assert');
+const http = require('http');
+const { callFmodeWecomGateway } = require('../mcp/src/providers/fmode-wecom-gateway');
+const { classifySubscribeError } = require('../mcp/src/core/subscribe-page');
+
+async function main() {
+  const server = http.createServer((req, res) => {
+    res.writeHead(409, { 'Content-Type': 'application/json' });
+    res.end(JSON.stringify({ code: 500, mess: '上游账号当前没有可用企微登录数量,请稍后重试' }));
+  });
+  await new Promise(resolve => server.listen(0, '127.0.0.1', resolve));
+  try {
+    const apiBase = `http://127.0.0.1:${server.address().port}`;
+    await assert.rejects(
+      () => callFmodeWecomGateway({ gatewayPath: '/login/start', token: 'r:smoke-session', apiBase }),
+      error => {
+        assert.strictEqual(error.httpStatus, 409);
+        assert.strictEqual(
+          classifySubscribeError(error.httpStatus, error.bizMessage),
+          'QW-UP-409'
+        );
+        return true;
+      }
+    );
+    console.log('[ok] preserves 409 capacity conflicts when upstream body code is 500');
+  } finally {
+    await new Promise(resolve => server.close(resolve));
+  }
+}
+
+main().catch(error => {
+  console.error(error);
+  process.exitCode = 1;
+});