Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix: close final-review findings in member-registration error handling
Jose Ramirez5b462496368e
diff --git a/control-api/src/memberRegistrationServiceClient.ts b/control-api/src/memberRegistrationServiceClient.tsindex 581749ecf..84ee327e5 100644--- a/control-api/src/memberRegistrationServiceClient.ts+++ b/control-api/src/memberRegistrationServiceClient.ts@@ -12,7 +12,14 @@ import {type RequestMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE'-const SEND_TIMEOUT_MS = 10_000+// This bounds a stalled hub, but does not guarantee the send didn't happen:+// if the hub's synchronous send exceeds it, we abort and return 503 while the+// hub may already have sent the mail — leaving the invitation in `draft`+// (which cleanupStaleDraftInvitations later deletes) and the invitee holding+// a dead link. 30s is chosen over the enrollment path's MINT_TIMEOUT_MS+// (10_000, memberRegistrationEnrollment.ts) to give a loaded SMTP send room+// to finish.+const SEND_TIMEOUT_MS = 30_000function buildUrl(baseUrl: string, path: string): string {const base = baseUrl.replace(/\/+$/, '')@@ -101,12 +108,9 @@ export async function memberRegistrationServiceRequest<T>(// routes/external/teams.ts:36 (spec §4.1).if (response.status >= 500) {// NOTE: this message must NOT contain the exact string "Member registration- // service" (capital M) — routes/admin/teams.ts:97,157 and- // routes/external/teams.ts:55 call sendInvitationServiceError(res, error)- // before next(error), which matches via message.includes('Member- // registration service'). If this 5xx message matched that string, a typed- // MemberRegistrationUnavailableError would be silently swallowed into a- // 502 invitation_service_unavailable instead of the intended 503.+ // service" (capital M) — that exact string is reserved for the untyped 4xx+ // path below, which routes/external/invitations.ts:212 and the+ // sendInvitationServiceError helpers match on.throw unavailable({ ...context, upstreamStatus: response.status },`member-registration service ${method} ${path} failed (${response.status})`diff --git a/control-api/test/memberRegistrationClient.errors.test.ts b/control-api/test/memberRegistrationClient.errors.test.tsindex 9751522d4..9ad3961e4 100644--- a/control-api/test/memberRegistrationClient.errors.test.ts+++ b/control-api/test/memberRegistrationClient.errors.test.ts@@ -96,6 +96,12 @@ describe('member-registration client failure classification', () => {expect(error).toBeInstanceOf(MemberRegistrationUnavailableError)expect(error.message).not.toContain('SECRET_BODY')expect(error.message).toContain('500')+ // Pins the invariant the comment above the 5xx throw documents: this+ // message must never collide with the untyped 4xx prefix, or a typed+ // MemberRegistrationUnavailableError would be matched by+ // sendInvitationServiceError's message.includes('Member registration+ // service') check.+ expect(error.message).not.toContain('Member registration service')})it('REGRESSION: an upstream 404 keeps the legacy plain Error and message so routes still match (spec §4.1)', async () => {@@ -147,10 +153,14 @@ describe('member-registration client failure classification', () => {})it('REGRESSION: a non-JSON 2xx does not leak body snippet from SyntaxError.message into logs', async () => {+ // V8 embeds only the first ~10 characters of the offending input in+ // SyntaxError.message (e.g. JSON.parse('<html>...') -> "...\"<html>SECR\"...+ // is not valid JSON"). The marker must sit inside that window, or this+ // assertion passes regardless of whether the bug is present.vi.stubGlobal('fetch',vi.fn().mockResolvedValue(- new Response('<html>SECRET_BODY_MARKER</html>', {+ new Response('SECRETMARKER-not-json', {status: 200,headers: { 'content-type': 'text/html' },})@@ -162,6 +172,9 @@ describe('member-registration client failure classification', () => {expect(logger.rootLogger.error).toHaveBeenCalled()// Verify the logged object does not contain the body snippetconst [loggedObject] = logger.rootLogger.error.mock.calls[0]- expect(JSON.stringify(loggedObject)).not.toContain('SECRET_BODY_MARKER')+ expect(JSON.stringify(loggedObject)).not.toContain('SECRETMARK')+ // Verify directly that no cause was threaded through at all on this path+ // -- the parse SyntaxError must never be passed to unavailable() here.+ expect(loggedObject.cause).toBeUndefined()})})diff --git a/profile-ui/lib/api.ts b/profile-ui/lib/api.tsindex 182a19d07..5b4cf2413 100644--- a/profile-ui/lib/api.ts+++ b/profile-ui/lib/api.ts@@ -129,12 +129,12 @@ export async function apiSend(} catch {detail = text}- if (detail === 'member_registration_unavailable') {+ if (detail.includes('member_registration_unavailable')) {throw new Error("Invitations are unavailable — the member-registration service isn't configured or can't be reached. Check the server logs for details.")}- if (detail === 'member_registration_misconfigured') {+ if (detail.includes('member_registration_misconfigured')) {throw new Error('Invitations are unavailable — member registration is misconfigured. Check the server logs for details.')