Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(rpc-proxy): normalize upstream disconnect errors to structured JSON (R1-L3)
Diego Zacarias64e0a6dcbb86
diff --git a/external-rest-api/src/releaseManifest.ts b/external-rest-api/src/releaseManifest.tsindex 60e2c4d2a..4ca7b2106 100644--- a/external-rest-api/src/releaseManifest.ts+++ b/external-rest-api/src/releaseManifest.ts@@ -9,7 +9,7 @@ export type ReleaseManifest = {export const releaseManifest: ReleaseManifest = {releaseId: 'v0.7.0',externalRestApiVersion: '0.1.81',- rpcProxyVersion: '0.1.71',+ rpcProxyVersion: '0.1.72',desktopVersion: '0.7.0',minimumDesktopVersion: '0.1.252',}diff --git a/rpc-proxy/package-lock.json b/rpc-proxy/package-lock.jsonindex cd3d293ac..bfac45897 100644--- a/rpc-proxy/package-lock.json+++ b/rpc-proxy/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-rpc-proxy",- "version": "0.1.71",+ "version": "0.1.72","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-rpc-proxy",- "version": "0.1.71",+ "version": "0.1.72","dependencies": {"cors": "^2.8.5","express": "^4.21.2",diff --git a/rpc-proxy/package.json b/rpc-proxy/package.jsonindex 2d3cf2e39..8d4faf29f 100644--- a/rpc-proxy/package.json+++ b/rpc-proxy/package.json@@ -1,6 +1,6 @@{"name": "clerum-rpc-proxy",- "version": "0.1.71",+ "version": "0.1.72","description": "External-facing RPC proxy for tenant-scoped MCP access","main": "dist/main.js","engines": {diff --git a/rpc-proxy/src/routes/mcpOauth.ts b/rpc-proxy/src/routes/mcpOauth.tsindex ad9e8b364..e82e0cbf7 100644--- a/rpc-proxy/src/routes/mcpOauth.ts+++ b/rpc-proxy/src/routes/mcpOauth.ts@@ -215,12 +215,22 @@ export function createMcpOauthRouter(): Router {return}- // Forward the upstream JSON error verbatim.+ // Forward the upstream error, but ALWAYS as application/json with a+ // structured body, preserving the upstream STATUS. control-api answers+ // JSON errors, but an intermediary (nginx, an ingress) can interpose an+ // HTML error page; reflecting its `content-type`/body would hand the+ // desktop `text/html` it can't parse. Parse the body as JSON when+ // possible; otherwise synthesize a structured error.const upstreamText = await upstream.text().catch(() => '')+ let parsed: unknown+ try {+ parsed = upstreamText ? JSON.parse(upstreamText) : null+ } catch {+ parsed = null+ }res.status(upstream.status)- .type(upstream.headers.get('content-type') ?? 'application/json')- .send(upstreamText)+ .json(parsed && typeof parsed === 'object' ? parsed : { error: 'control_api_error' })})diff --git a/rpc-proxy/src/routes/mcpOauthDisconnect.test.ts b/rpc-proxy/src/routes/mcpOauthDisconnect.test.tsindex 93105eeef..819a7dd81 100644--- a/rpc-proxy/src/routes/mcpOauthDisconnect.test.ts+++ b/rpc-proxy/src/routes/mcpOauthDisconnect.test.ts@@ -171,4 +171,28 @@ describe('DELETE /api/v1/mcp-oauth/:mcpServerName/grant (spec 11 U4 disconnect)'expect(res.body.error).toBe('control_api_invalid_response')warnSpy.mockRestore()})++ it('rewrites an upstream HTML error page to structured JSON, preserving status (R1-L3)', async () => {+ // An ingress/nginx can interpose a text/html 403 page; the desktop must+ // never receive reflected HTML.+ fetchSpy.mockResolvedValue(+ new Response('<html><body>403 Forbidden</body></html>', {+ status: 403,+ headers: { 'content-type': 'text/html' },+ })+ )+ const res = await request(makeApp()).delete(PATH).set('Authorization', 'Bearer t').send({})+ expect(res.status).toBe(403)+ expect(res.headers['content-type']).toMatch(/application\/json/)+ expect(res.body.error).toBe('control_api_error')+ expect(JSON.stringify(res.body)).not.toContain('<html')+ })++ it('preserves a structured JSON error body from control-api as JSON (R1-L3)', async () => {+ fetchSpy.mockResolvedValue(jsonResponse(400, { error: 'not_oauth_server' }))+ const res = await request(makeApp()).delete(PATH).set('Authorization', 'Bearer t').send({})+ expect(res.status).toBe(400)+ expect(res.headers['content-type']).toMatch(/application\/json/)+ expect(res.body.error).toBe('not_oauth_server')+ })})