{"record":{"id":"9672dd072eb73480","repo":"hcengineering/platform","slug":"unknownstatus-err-message","errorCode":null,"errorMessage":"unknownStatus(err.message)","messagePattern":"unknownStatus\\(err\\.message\\)","errorType":"http","errorClass":"Status","httpStatus":400,"severity":"error","filePath":"server/account-service/src/index.ts","lineNumber":440,"sourceCode":"          }\n\n          ctx.res.writeHead(400, KEEP_ALIVE_HEADERS)\n          ctx.res.end(JSON.stringify(response))\n          return\n        }\n\n        try {\n          const result = await method(_ctx, db, branding, request, token, meta)\n\n          const body = JSON.stringify(result)\n          ctx.res.writeHead(200, KEEP_ALIVE_HEADERS)\n          ctx.res.end(body)\n        } catch (err: any) {\n          const response = {\n            id: request.id,\n            error: unknownStatus(err.message)\n          }\n          ctx.res.writeHead(400, KEEP_ALIVE_HEADERS)\n          ctx.res.end(JSON.stringify(response))\n        }\n      },\n      { method: request.method }\n    )\n  })\n\n  app.use(router.routes()).use(router.allowedMethods())\n\n  const server = app.listen(ACCOUNT_PORT, () => {\n    console.log(`server started on port ${ACCOUNT_PORT}`)\n  })\n\n  const close = (): void => {\n    onClose?.()\n    void accountsDb.then(([, closeAccountsDb]) => {\n      closeAccountsDb()\n    })","sourceCodeStart":422,"sourceCodeEnd":458,"githubUrl":"https://github.com/hcengineering/platform/blob/63e28dc96483967b2fc21c881b3f1023c1de7718/server/account-service/src/index.ts#L422-L458","documentation":"When a method handler throws inside serveAccount, the catch block converts the raw error message into a Status via unknownStatus(err.message) and returns it as a 400 response. This entry exists because the thrown message did not match any known status mapping, so the service wraps whatever text arrived into an error response generically.","triggerScenarios":"Any uncaught exception inside a method handler invoked by serveAccount — e.g. DB errors, validation failures, or thrown strings — reaches this catch and gets funneled through unknownStatus(err.message).","commonSituations":"Handler code throws a plain string or an error whose message isn't in the status registry; unhandled promise rejection in a method; network/DB outage causing raw driver errors to bubble up as 400s.","solutions":["Inspect the err.message in the 400 response body — it contains the original error text","Fix the root cause in the method handler that threw (check service logs for the stack)","If the message should be a known status, add/register it in the status mapping used by unknownStatus","Throw Status objects (not raw strings) from handlers so they map correctly"],"exampleFix":"// before\nthrow new Error('user not found')\n// after\nthrow new Status(Severity.ERROR, platform.status.NotFound, { user: id })","handlingStrategy":"try-catch","validationCode":"// validate inputs expected by the handler before calling RPC\nif (!request || typeof request.method !== 'function') throw new Error('invalid request')","typeGuard":null,"tryCatchPattern":"try {\n  const res = await rpc(method, args)\n} catch (e) {\n  const status = e?.error // unknownStatus(err.message) output\n  console.error('RPC failed:', status?.message ?? e.message)\n}","preventionTips":["Throw structured Status objects from handlers, not raw strings/Errors","Register all handler-thrown messages in the status mapping","Wrap each method body with its own try/catch and meaningful Status","Alert on 400 responses whose error text doesn't match a known status"],"tags":["error-handling","rpc","unhandled-exception"],"backgroundTag":"unhandled-handler-exception","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}