{"record":{"id":"dc22808f0691689f","repo":"medusajs/medusa","slug":"role-with-id-req-params-id-not-found","errorCode":null,"errorMessage":"Role with id: ${req.params.id} not found","messagePattern":"Role with id: (.+?) not found","errorType":"exception","errorClass":"MedusaError","httpStatus":404,"severity":"error","filePath":"packages/medusa/src/api/admin/rbac/roles/[id]/route.ts","lineNumber":34,"sourceCode":"/**\n * @ignore\n * @featureFlag rbac\n */\nexport const GET = async (\n  req: AuthenticatedMedusaRequest,\n  res: MedusaResponse\n) => {\n  const query = req.scope.resolve(ContainerRegistrationKeys.QUERY)\n  const { data: roles } = await query.graph({\n    entity: \"rbac_role\",\n    filters: { id: req.params.id },\n    fields: req.queryConfig.fields,\n  })\n\n  const role = roles[0]\n\n  if (!role) {\n    throw new MedusaError(\n      MedusaError.Types.NOT_FOUND,\n      `Role with id: ${req.params.id} not found`\n    )\n  }\n\n  res.status(200).json({ role })\n}\n\n/**\n * @ignore\n * @featureFlag rbac\n */\nexport const POST = async (\n  req: AuthenticatedMedusaRequest<AdminUpdateRbacRoleType>,\n  res: MedusaResponse\n) => {\n  const query = req.scope.resolve(ContainerRegistrationKeys.QUERY)\n  const { data: existing } = await query.graph({","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/medusajs/medusa/blob/5e06e544a296b9033f20f71f11c559f81a0e5739/packages/medusa/src/api/admin/rbac/roles/[id]/route.ts#L16-L52","documentation":"Thrown by GET /admin/rbac/roles/:id when the RBAC role query returns an empty array. The role is fetched by id with the requested fields; a missing role triggers NOT_FOUND.","triggerScenarios":"Calling GET /admin/rbac/roles/role_123 for a role id that was deleted or never existed.","commonSituations":"Role pickers holding stale role lists after roles were deleted/renamed, user-assignment flows referencing removed roles, or wrong-environment ids in provisioning scripts.","solutions":["List roles (GET /admin/rbac/roles) and use current ids","If a role was deleted but still referenced, either recreate it or remove the references","Provisioning scripts should check role existence (or create-if-missing) before assigning"],"exampleFix":"// before\nconst { role } = await sdk.client.fetch(`/admin/rbac/roles/${id}`)\n\n// after\nconst { roles } = await sdk.client.fetch(\"/admin/rbac/roles\")\nconst role = roles.find((r) => r.id === id)\nif (!role) throw new Error(`Role ${id} no longer exists`)","handlingStrategy":"validation","validationCode":"const { roles } = await sdk.client.fetch(\"/admin/rbac/roles\")\nif (!roles.some((r) => r.id === roleId)) throw new Error(`Role ${roleId} not found`)","typeGuard":"const isRole = (v: unknown): v is { id: string } & Record<string, unknown> =>\n  !!v && typeof v === \"object\" && \"id\" in v","tryCatchPattern":"try {\n  return await getRole(id)\n} catch (e: any) {\n  if (e.statusCode === 404) { refreshRoles(); return null }\n  throw e\n}","preventionTips":["Provisioning scripts: check-or-create roles before assigning","Refresh role pickers after role deletions","Remove references to deleted roles from user assignment flows"],"tags":["admin","rbac","roles","not-found","rest-api"],"backgroundTag":"resource-not-found","analyzedSha":"5e06e544a296b9033f20f71f11c559f81a0e5739","analyzedAt":"2026-08-27T07:24:39.599Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}