Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

fix(control-api): read .httpStatus in extractErrorStatus so K8s 404 forwards as 404 (R4-M3)

Diego Zacarias86b90db350a8
diff --git a/control-api/package-lock.json b/control-api/package-lock.json
index f72bfaab7..6006e9e13 100644
--- a/control-api/package-lock.json
+++ b/control-api/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-control-api",
- "version": "0.1.444",
+ "version": "0.1.445",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-control-api",
- "version": "0.1.444",
+ "version": "0.1.445",
"dependencies": {
"@clerum/image-policy": "file:../packages/image-policy",
"@clerum/llm-providers": "file:../packages/llm-providers",
diff --git a/control-api/package.json b/control-api/package.json
index cad177848..383884035 100644
--- a/control-api/package.json
+++ b/control-api/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-control-api",
- "version": "0.1.444",
+ "version": "0.1.445",
"description": "Internal Clerum control plane REST API + UI for managing CRDs and secrets",
"main": "dist/main.js",
"engines": {
diff --git a/control-api/src/http/errorHandler.ts b/control-api/src/http/errorHandler.ts
index a5b7714b1..07581b4b2 100644
--- a/control-api/src/http/errorHandler.ts
+++ b/control-api/src/http/errorHandler.ts
@@ -27,11 +27,16 @@ function extractErrorStatus(err: unknown): number | undefined {
status?: unknown
statusCode?: unknown
code?: unknown
+ httpStatus?: unknown
response?: { statusCode?: unknown; status?: unknown }
}
if (typeof maybe.status === 'number') return maybe.status
if (typeof maybe.statusCode === 'number') return maybe.statusCode
if (typeof maybe.code === 'number') return maybe.code
+ // `.httpStatus` mirrors extractK8sError's chain (http/k8sError.ts): the
+ // service-layer K8sNotFoundError/K8sConflictError expose their status there,
+ // so read it after code/statusCode or their 404/409 collapses to 500.
+ if (typeof maybe.httpStatus === 'number') return maybe.httpStatus
if (maybe.response && typeof maybe.response.statusCode === 'number') {
return maybe.response.statusCode
}
diff --git a/control-api/test/http.errorHandler.k8sStatus.test.ts b/control-api/test/http.errorHandler.k8sStatus.test.ts
index 513dde373..1ca0fe60b 100644
--- a/control-api/test/http.errorHandler.k8sStatus.test.ts
+++ b/control-api/test/http.errorHandler.k8sStatus.test.ts
@@ -4,6 +4,7 @@ import type { Request } from 'express'
import { ApiException } from '@kubernetes/client-node'
import request from 'supertest'
import { clerumErrorHandler } from '../src/http/errorHandler.js'
+import { K8sNotFoundError } from '../src/services/resourceService.js'
/**
* UT-2a (FIX-B): the global error handler must forward a K8s error's real 4xx
@@ -61,6 +62,25 @@ describe('clerumErrorHandler — K8s status forwarding (UT-2a)', () => {
expect(res.status).toBe(404)
})
+ /**
+ * R4-M3: the service-layer K8sNotFoundError/K8sConflictError expose their
+ * status ONLY on `.httpStatus` (no `.status` / `.statusCode` / `.code`). The
+ * handler's status chain must read `.httpStatus`, otherwise a real 404
+ * collapses to 500. Fixture derived from the real producer (T1): an actual
+ * `K8sNotFoundError` instance, not a hand-built `{ httpStatus }` object.
+ */
+ it('forwards a K8sNotFoundError (status only on `.httpStatus`) as 404', async () => {
+ const err = new K8sNotFoundError('host "product-agent" not found')
+ // Sanity: the real producer carries its status on `.httpStatus` alone.
+ expect((err as unknown as { httpStatus: number }).httpStatus).toBe(404)
+ expect((err as unknown as { status?: unknown }).status).toBeUndefined()
+ expect((err as unknown as { statusCode?: unknown }).statusCode).toBeUndefined()
+ expect((err as unknown as { code?: unknown }).code).toBeUndefined()
+
+ const res = await request(appThrowing(err)).get('/boom')
+ expect(res.status).toBe(404)
+ })
+
it('does NOT forward a 5xx code — {code:500} still collapses to 500', async () => {
const res = await request(appThrowing({ code: 500 })).get('/boom')
expect(res.status).toBe(500)