{"record":{"id":"37ba9d944cbf86cf","repo":"diegosouzapw/OmniRoute","slug":"serviceapikeydecrypterror","errorCode":null,"errorMessage":"ServiceApiKeyDecryptError","messagePattern":"ServiceApiKeyDecryptError","errorType":"exception","errorClass":"ServiceApiKeyDecryptError","httpStatus":null,"severity":"error","filePath":"src/lib/services/apiKey.ts","lineNumber":29,"sourceCode":"    super(\n      `Stored API key for service '${tool}' could not be decrypted. ` +\n        `STORAGE_ENCRYPTION_KEY may have changed, the row may be corrupted, ` +\n        `or it was written on a different machine. Reinstall the service ` +\n        `or rotate the key via POST /api/services/${tool}/rotate-key.`\n    );\n    this.name = \"ServiceApiKeyDecryptError\";\n  }\n}\n\nexport async function getOrCreateApiKey(tool: string): Promise<string> {\n  const row = await getServiceRow(tool);\n  if (row?.apiKey) {\n    const decrypted = decrypt(row.apiKey);\n    if (decrypted) return decrypted;\n    // Fail loud: silently regenerating would mint a new key the embedded\n    // service has never been told, causing every request to 401 with no\n    // operator-facing signal.\n    throw new ServiceApiKeyDecryptError(tool);\n  }\n  // Dario reuses this mechanism to generate+persist its DARIO_ADMIN_TOKEN\n  // (any long random string works — it gates the /admin/* control plane).\n  const prefix =\n    tool === \"9router\" ? \"nr\" : tool === \"mux\" ? \"mx\" : tool === \"dario\" ? \"da\" : \"cp\";\n  const key = generateServiceApiKey(prefix);\n  await updateServiceField(tool, \"apiKey\", encrypt(key) ?? key);\n  return key;\n}\n\nexport function maskApiKey(plainKey: string): string {\n  const last4 = plainKey.slice(-4);\n  return `nr_••••••••${last4}`;\n}\n","sourceCodeStart":11,"sourceCodeEnd":44,"githubUrl":"https://github.com/diegosouzapw/OmniRoute/blob/a179ffed5bb2e0b883b9ae7214ce8717b2a94c4d/src/lib/services/apiKey.ts#L11-L44","documentation":"Error \"ServiceApiKeyDecryptError\" thrown in diegosouzapw/OmniRoute.","triggerScenarios":"Thrown at src/lib/services/apiKey.ts:29 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"a179ffed5bb2e0b883b9ae7214ce8717b2a94c4d","analyzedAt":"2026-08-25T18:35:09.898Z","schemaVersion":2},"datasetVersion":"2026-08-25T21:54:21.419Z"}