{"record":{"id":"a4b04fea3383fa43","repo":"apolloconfig/apollo","slug":"consumerapp-not-exist","errorCode":null,"errorMessage":"ConsumerApp not exist","messagePattern":"ConsumerApp not exist","errorType":"validation","errorClass":"BadRequestException","httpStatus":400,"severity":"error","filePath":"apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/service/ConsumerService.java","lineNumber":480,"sourceCode":"\n    List<ConsumerInfo> consumerInfoList = new ArrayList<>(consumerList.size());\n\n    for (int i = 0; i < consumerList.size(); i++) {\n      Consumer consumer = consumerList.get(i);\n      // without token\n      ConsumerInfo consumerInfo = convert(consumer, null, allowCreateApplicationList.get(i),\n          allowManageUsersList.get(i), rateLimitList.get(i));\n      consumerInfoList.add(consumerInfo);\n    }\n\n    return consumerInfoList;\n  }\n\n  @Transactional\n  public void deleteConsumer(String appId) {\n    Consumer consumer = consumerRepository.findByAppId(appId);\n    if (consumer == null) {\n      throw new BadRequestException(\"ConsumerApp not exist\");\n    }\n    long consumerId = consumer.getId();\n    List<ConsumerRole> consumerRoleList = consumerRoleRepository.findByConsumerId(consumerId);\n    ConsumerToken consumerToken = consumerTokenRepository.findByConsumerId(consumerId);\n\n    consumerRoleRepository.deleteAll(consumerRoleList);\n    consumerRepository.delete(consumer);\n\n    if (Objects.nonNull(consumerToken)) {\n      consumerTokenRepository.delete(consumerToken);\n    }\n  }\n\n}\n","sourceCodeStart":462,"sourceCodeEnd":495,"githubUrl":"https://github.com/apolloconfig/apollo/blob/d95fc18d112589efc09ddcbe1507047584d55251/apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/service/ConsumerService.java#L462-L495","documentation":"Thrown by ConsumerService.deleteConsumer when no Consumer record is found for the given appId. The method queries consumerRepository.findByAppId(appId). This is used to remove an OpenAPI consumer application and all its associated roles and tokens. If the appId does not correspond to any registered consumer app, deletion cannot proceed. Results in HTTP 400.","triggerScenarios":"Calling deleteConsumer(appId) with an appId that was never registered as a consumer app, has already been deleted, or is an actual Apollo application appId rather than a consumer-app appId.","commonSituations":"Attempting to delete a consumer app that was already removed in a previous operation. Confusing the consumer-app appId with a regular Apollo application appId. The consumer record was manually deleted from the DB, leaving stale references elsewhere.","solutions":["Verify the appId exists as a Consumer record via consumerRepository.findByAppId(appId) before calling deleteConsumer.","Check whether the consumer was already deleted (idempotent delete handling).","Ensure you are using the consumer app's own appId, not a target Apollo application's appId."],"exampleFix":"// before\nconsumerService.deleteConsumer(appId);\n\n// after\nConsumer existing = consumerRepository.findByAppId(appId);\nif (existing == null) {\n    // already deleted or never existed — treat as no-op or return 404\n    return;\n}\nconsumerService.deleteConsumer(appId);","handlingStrategy":"validation","validationCode":"// Check consumer existence before deletion (idempotent delete)\nConsumer existing = consumerRepository.findByAppId(appId);\nif (existing == null) {\n    log.info(\"Consumer app {} not found, treating delete as no-op\", appId);\n    return;\n}\nconsumerService.deleteConsumer(appId);","typeGuard":null,"tryCatchPattern":"try {\n    consumerService.deleteConsumer(appId);\n} catch (BadRequestException e) {\n    if (\"ConsumerApp not exist\".equals(e.getMessage())) {\n        // Idempotent: already deleted, no action needed\n        return;\n    }\n    throw e;\n}","preventionTips":["Make delete operations idempotent by catching 'ConsumerApp not exist' and treating it as success.","Verify the consumer appId is distinct from regular Apollo application appIds.","Log delete attempts for audit trail even when the target is already absent."],"tags":["openapi","consumer-management","apollo-portal","delete","validation"],"backgroundTag":null,"analyzedSha":"d95fc18d112589efc09ddcbe1507047584d55251","analyzedAt":"2026-08-14T04:00:05.477Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}