Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(control-api): read .httpStatus in extractHttpStatus so K8s errors map to 404/409 (R5-M1)
Diego Zacariasdbbb712bd6b1
diff --git a/control-api/package-lock.json b/control-api/package-lock.jsonindex e20f35bb9..541e21f43 100644--- a/control-api/package-lock.json+++ b/control-api/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-control-api",- "version": "0.1.447",+ "version": "0.1.448","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-control-api",- "version": "0.1.447",+ "version": "0.1.448","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.jsonindex 7ce1538ed..97cb53ceb 100644--- a/control-api/package.json+++ b/control-api/package.json@@ -1,6 +1,6 @@{"name": "clerum-control-api",- "version": "0.1.447",+ "version": "0.1.448","description": "Internal Clerum control plane REST API + UI for managing CRDs and secrets","main": "dist/main.js","engines": {diff --git a/control-api/src/k8s.ts b/control-api/src/k8s.tsindex be27971b6..1a73e257f 100644--- a/control-api/src/k8s.ts+++ b/control-api/src/k8s.ts@@ -681,11 +681,16 @@ export function extractHttpStatus(err: unknown): number | null {const maybe = err as {statusCode?: numbercode?: number | string+ httpStatus?: numberresponse?: { statusCode?: number; status?: number }}if (typeof maybe.statusCode === 'number') return maybe.statusCodeif (typeof maybe.code === 'number') return maybe.codeif (typeof maybe.code === 'string' && /^\d+$/.test(maybe.code)) return Number(maybe.code)+ // `.httpStatus` mirrors extractK8sError's chain (http/k8sError.ts): the+ // service-layer K8sNotFoundError/K8sConflictError expose their status only+ // there, so read it after code/statusCode or their 404/409 collapses to null.+ if (typeof maybe.httpStatus === 'number') return maybe.httpStatusif (maybe.response && typeof maybe.response.statusCode === 'number')return maybe.response.statusCodeif (maybe.response && typeof maybe.response.status === 'number') return maybe.response.statusdiff --git a/control-api/test/k8s.extractHttpStatus.test.ts b/control-api/test/k8s.extractHttpStatus.test.tsnew file mode 100644index 000000000..d4a8a891f--- /dev/null+++ b/control-api/test/k8s.extractHttpStatus.test.ts@@ -0,0 +1,23 @@+import { describe, expect, it } from 'vitest'+import { extractHttpStatus } from '../src/k8s.js'+// Fixtures are derived from the REAL producers (T1): the service layer throws+// these classes, which expose their status ONLY via `readonly httpStatus`, with+// no `code`/`statusCode`. Hand-building `{ httpStatus: 404 }` would encode a+// belief about their shape instead of the shape they actually emit.+import { K8sConflictError, K8sNotFoundError } from '../src/services/resourceService.js'++describe('extractHttpStatus', () => {+ it('reads httpStatus from a real K8sNotFoundError (was null before the fix)', () => {+ // Consumer: routes/admin/secrets.ts:462 branches on === 404 to answer a+ // rotation against a missing Secret with a proper 404 instead of throwing.+ expect(extractHttpStatus(new K8sNotFoundError('Secret "x" not found'))).toBe(404)+ })++ it('reads httpStatus from a real K8sConflictError', () => {+ expect(extractHttpStatus(new K8sConflictError('resourceVersion conflict'))).toBe(409)+ })++ it('still prefers statusCode when present (precedence unchanged)', () => {+ expect(extractHttpStatus({ statusCode: 500 })).toBe(500)+ })+})