{"record":{"id":"a80bcc3f00e17980","repo":"langfuse/langfuse","slug":"internal-server-error-a80bcc","errorCode":null,"errorMessage":"Internal server error","messagePattern":"Internal server error","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"web/src/pages/api/admin/organizations/[organizationId]/apiKeys/index.ts","lineNumber":65,"sourceCode":"    });\n\n    if (!organization) {\n      return res.status(404).json({ error: \"Organization not found\" });\n    }\n\n    // Handle different HTTP methods\n    switch (req.method) {\n      case \"GET\":\n        return await handleGetApiKeys(req, res, organizationId);\n      case \"POST\":\n        return await handleCreateApiKey(req, res, organizationId);\n      default:\n        res.status(405).json({ error: \"Method Not Allowed\" });\n        return;\n    }\n  } catch (e) {\n    logger.error(\"Failed to process organization API key request\", e);\n    res.status(500).json({ error: \"Internal server error\" });\n  }\n}\n","sourceCodeStart":47,"sourceCodeEnd":68,"githubUrl":"https://github.com/langfuse/langfuse/blob/59d92c7cf365150d10b753b5a0d1708902a2ed60/web/src/pages/api/admin/organizations/[organizationId]/apiKeys/index.ts#L47-L68","documentation":"500 catch-all for the apiKeys collection handler. Any unhandled exception from the entitlement check onward — Prisma errors in handleGetApiKeys/handleCreateApiKey, invalid body shapes, unique constraint violations on new keys — surfaces here after being logged.","triggerScenarios":"POST with malformed JSON body that fails inside the create sub-handler; prisma.organizationApiKeys create colliding on unique(publicId); DB unavailable.","commonSituations":"Creating an API key on an org while another request does the same; body not matching the expected schema; self-hosted DB migrations not applied so the organizationApiKeys table is missing columns.","solutions":["Read the logged exception ('Failed to process organization API key request') to identify the sub-handler that threw","Validate the POST body against the route's expected schema before sending","Run prisma migrations if the schema is out of date","Handle 409/unique conflicts by regenerating the key id and retrying"],"exampleFix":"// before\nconst res = await fetch(url, { method: 'POST', body: JSON.stringify(maybeWrongShape) });\n// after\nconst body = { note: 'my key' }; // match route schema\nconst res = await fetch(url, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify(body) });\nif (!res.ok) throw new Error(`admin api failed: ${res.status}`);","handlingStrategy":"try-catch","validationCode":"const body = { note: 'string' };\nconst ok = typeof body.note === 'string';","typeGuard":"null","tryCatchPattern":"try { const r = await adminFetch(url, {...}); if (r.status >= 500) throw await r.text(); } catch (e) { /* inspect server logs, surface to user */ }","preventionTips":["Validate request bodies client-side against the route schema","Apply DB migrations before deploying API consumers"],"tags":["http-500","prisma","admin-api","catch-all"],"backgroundTag":"internal-server-error","analyzedSha":"59d92c7cf365150d10b753b5a0d1708902a2ed60","analyzedAt":"2026-08-27T22:22:00.402Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}