{"record":{"id":"628185602e7c847c","repo":"apolloconfig/apollo","slug":"app-s-role-does-not-exist-please-check-whether-ap","errorCode":null,"errorMessage":"App's role does not exist. Please check whether app has created.","messagePattern":"App's role does not exist\\. Please check whether app has created\\.","errorType":"validation","errorClass":"BadRequestException","httpStatus":400,"severity":"error","filePath":"apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/service/ConsumerService.java","lineNumber":338,"sourceCode":"\n  @Transactional\n  public ConsumerRole assignAppRoleToConsumer(String token, String appId, String operator) {\n    validateOperator(operator);\n    Long consumerId = getConsumerIdByToken(token);\n    return assignAppRoleToConsumer(consumerId, appId, operator);\n  }\n\n  @Transactional\n  public ConsumerRole assignAppRoleToConsumer(Long consumerId, String appId, String operator) {\n    validateOperator(operator);\n    if (consumerId == null) {\n      throw new BadRequestException(\"Token is Illegal\");\n    }\n\n    Role masterRole =\n        rolePermissionService.findRoleByRoleName(RoleUtils.buildAppMasterRoleName(appId));\n    if (masterRole == null) {\n      throw new BadRequestException(\n          \"App's role does not exist. Please check whether app has created.\");\n    }\n\n    long roleId = masterRole.getId();\n    ConsumerRole managedModifyRole =\n        consumerRoleRepository.findByConsumerIdAndRoleId(consumerId, roleId);\n    if (managedModifyRole != null) {\n      return managedModifyRole;\n    }\n\n    ConsumerRole consumerRole = createConsumerRole(consumerId, roleId, operator);\n    return consumerRoleRepository.save(consumerRole);\n  }\n\n  @Transactional\n  public void createConsumerAudits(Iterable<ConsumerAudit> consumerAudits) {\n    consumerAuditRepository.saveAll(consumerAudits);\n  }","sourceCodeStart":320,"sourceCodeEnd":356,"githubUrl":"https://github.com/apolloconfig/apollo/blob/d95fc18d112589efc09ddcbe1507047584d55251/apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/service/ConsumerService.java#L320-L356","documentation":"Thrown by assignAppRoleToConsumer when the app's master role does not exist. The method looks up RoleUtils.buildAppMasterRoleName(appId) via rolePermissionService.findRoleByRoleName. Apollo creates the master role (and other app roles) during app creation. If the role is absent, the app was either never fully created through the Portal, or the role initialization failed. Results in HTTP 400.","triggerScenarios":"Calling assignAppRoleToConsumer for an appId that has no corresponding app-master role row in the permission system. This happens when the app was created in an environment but the Portal DB role-seeding step was skipped or partially completed, or the appId is for a consumer-app record that was never a real Apollo application.","commonSituations":"The appId refers to a consumer token's appId (a technical identifier), not an actual Apollo application appId. The app was created directly in configservice/adminservice DB without going through Portal, so roles were never seeded. Cross-environment confusion: the app exists in DEV but role assignment is attempted against a portal DB that does not have it.","solutions":["Verify the app was created through the Portal UI/API (not inserted directly into the DB) so that role initialization completes.","Confirm the appId you are passing matches an actual Apollo application appId, not a consumer-app identifier.","Check the Role table in the portal DB for a row with role_name matching 'Master+<appId>' (via RoleUtils.buildAppMasterRoleName) — if absent, recreate the app.","If the app exists but roles are missing, re-trigger role initialization by calling the app-creation path or a repair script."],"exampleFix":"// before\nconsumerService.assignAppRoleToConsumer(consumerId, appId, operator);\n\n// after\nRole masterRole = rolePermissionService.findRoleByRoleName(RoleUtils.buildAppMasterRoleName(appId));\nif (masterRole == null) {\n    throw new IllegalStateException(\n        \"App \" + appId + \" has no master role; create the app via Portal first\");\n}\nconsumerService.assignAppRoleToConsumer(consumerId, appId, operator);","handlingStrategy":"validation","validationCode":"// Verify the app master role exists before attempting role assignment\nRole masterRole = rolePermissionService.findRoleByRoleName(\n    RoleUtils.buildAppMasterRoleName(appId));\nif (masterRole == null) {\n    throw new IllegalStateException(\n        \"App \" + appId + \" has no master role. Create the app via Portal first.\");\n}\nconsumerService.assignAppRoleToConsumer(consumerId, appId, operator);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always create apps through the Portal or the app-creation API so role initialization is automatic.","Before bulk-assigning consumer roles, run a pre-check that verifies master roles exist for all target appIds.","Never insert app records directly into the DB; the role-seeding step will be skipped."],"tags":["openapi","role-assignment","apollo-portal","app-creation","permission-system"],"backgroundTag":null,"analyzedSha":"d95fc18d112589efc09ddcbe1507047584d55251","analyzedAt":"2026-08-14T04:00:05.477Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}