fix: 统一上游不可达错误文案
This commit is contained in:
@@ -54,6 +54,45 @@ test("cloud web auth requests are proxied once", async () => {
|
||||
}
|
||||
});
|
||||
|
||||
test("cloud web proxy reports a unified upstream unavailable error", async () => {
|
||||
const cloudWeb = createCloudWebServer({
|
||||
serviceId: "hwlab-cloud-web",
|
||||
cloudApiBaseUrl: "http://127.0.0.1:1",
|
||||
cloudApiProxyTimeoutMs: 1000,
|
||||
healthPayload: () => ({ status: "ok" }),
|
||||
roots: [],
|
||||
sendJson(response, statusCode, body) {
|
||||
const payload = JSON.stringify(body);
|
||||
response.writeHead(statusCode, {
|
||||
"content-type": "application/json",
|
||||
"content-length": Buffer.byteLength(payload)
|
||||
});
|
||||
response.end(payload);
|
||||
}
|
||||
});
|
||||
await listen(cloudWeb);
|
||||
|
||||
try {
|
||||
const response = await fetch(`${serverUrl(cloudWeb)}/v1/web-performance/summary?window=15m`, {
|
||||
headers: { accept: "application/json", "x-trace-id": "trc_proxy_upstream_unavailable" }
|
||||
});
|
||||
assert.equal(response.status, 502);
|
||||
const payload = await response.json();
|
||||
assert.equal(payload.status, "failed");
|
||||
assert.equal(payload.error.code, "upstream_unavailable");
|
||||
assert.equal(payload.error.layer, "proxy");
|
||||
assert.equal(payload.error.retryable, true);
|
||||
assert.equal(payload.error.userMessage, "暂时无法连接上游。");
|
||||
assert.equal(payload.error.message, "暂时无法连接上游。");
|
||||
assert.equal(payload.error.blocker.code, "upstream_unavailable");
|
||||
assert.equal(payload.error.blocker.summary, "暂时无法连接上游。");
|
||||
assert.equal(payload.reason, "暂时无法连接上游。");
|
||||
assert.doesNotMatch(JSON.stringify(payload), /Code Agent|输入已保留|稍后重试/u);
|
||||
} finally {
|
||||
await close(cloudWeb);
|
||||
}
|
||||
});
|
||||
|
||||
test("cloud web proxies Admin Access write routes", async () => {
|
||||
const upstreamRequests = [];
|
||||
const upstream = createServer(async (request, response) => {
|
||||
|
||||
Reference in New Issue
Block a user