Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(control-ui): surface server error message from apiGet for registry-unavailable
Jose Ramirez1056085d8b85
diff --git a/control-ui/components/__tests__/RegistryCatalog.test.tsx b/control-ui/components/__tests__/RegistryCatalog.test.tsxindex d4250a639..dec4c7c1b 100644--- a/control-ui/components/__tests__/RegistryCatalog.test.tsx+++ b/control-ui/components/__tests__/RegistryCatalog.test.tsx@@ -362,6 +362,23 @@ describe('RegistryCatalog - loading and error states', () => {expect(screen.getByText('Error: 500 Internal Server Error')).toBeInTheDocument()})})++ it('test_registryCatalog_unavailable_showsFriendlyServerMessage', async () => {+ vi.mocked(api.getRegistryCatalog).mockRejectedValue(+ new Error('The registry is currently unavailable. Check the connection and try again.')+ )++ render(<RegistryCatalog />)++ await waitFor(() => {+ expect(+ screen.getByText(+ 'Error: The registry is currently unavailable. Check the connection and try again.'+ )+ ).toBeInTheDocument()+ })+ expect(screen.queryByText('Error: 500 Internal Server Error')).not.toBeInTheDocument()+ })})describe('RegistryCatalog - entry details', () => {diff --git a/control-ui/lib/__tests__/registryCatalogApi.test.ts b/control-ui/lib/__tests__/registryCatalogApi.test.tsindex 6ea121d13..83accf43f 100644--- a/control-ui/lib/__tests__/registryCatalogApi.test.ts+++ b/control-ui/lib/__tests__/registryCatalogApi.test.ts@@ -77,3 +77,23 @@ describe('registry catalog api — tags coercion', () => {expect(res.tags).toEqual([])})})++describe('registry catalog api — registry-unavailable error surface', () => {+ it('getRegistryCatalog surfaces the server message on a 503 registry_unavailable', async () => {+ fetchMock.mockResolvedValueOnce(+ makeRes(503, {+ error: 'registry_unavailable',+ message: 'The registry is currently unavailable. Check the connection and try again.',+ })+ )+ const err = (await getRegistryCatalog().catch(e => e)) as Error & {+ status?: number+ code?: string+ }+ expect(err.message).toBe(+ 'The registry is currently unavailable. Check the connection and try again.'+ )+ expect(err.status).toBe(503)+ expect(err.code).toBe('registry_unavailable')+ })+})diff --git a/control-ui/lib/api.ts b/control-ui/lib/api.tsindex 408d2535e..8259003f8 100644--- a/control-ui/lib/api.ts+++ b/control-ui/lib/api.ts@@ -193,8 +193,28 @@ export async function apiGet(}handleUnauthorized()}- const error = new Error(`${res.status} ${res.statusText}`)- ;(error as Error & { status?: number }).status = res.status+ // Prefer a server-provided human-safe `message` (e.g. the 503+ // registry_unavailable body) so callers surface the clear text instead of+ // a bare "<status> <statusText>". Bodies carrying only a machine `error`+ // code (or no JSON) keep the existing status-text message. Also attach the+ // machine code, mirroring how registryCodedRequest surfaces `.code`.+ const text = await res.text().catch(() => '')+ let message = `${res.status} ${res.statusText}`+ let code: string | undefined+ try {+ const parsed = JSON.parse(text) as { error?: unknown; message?: unknown }+ if (parsed && typeof parsed === 'object') {+ if (typeof parsed.message === 'string' && parsed.message.trim()) {+ message = parsed.message+ }+ if (typeof parsed.error === 'string') code = parsed.error+ }+ } catch {+ /* non-JSON error body: keep the status-text message */+ }+ const error = new Error(message) as Error & { status?: number; code?: string }+ error.status = res.status+ if (code) error.code = codethrow error}return parseJsonResponse(res)