apolloconfig/apollo · error · BadRequestException
ConsumerApp not exist
Error message
ConsumerApp not exist
What it means
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.
Source
Thrown at apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/service/ConsumerService.java:480
List<ConsumerInfo> consumerInfoList = new ArrayList<>(consumerList.size());
for (int i = 0; i < consumerList.size(); i++) {
Consumer consumer = consumerList.get(i);
// without token
ConsumerInfo consumerInfo = convert(consumer, null, allowCreateApplicationList.get(i),
allowManageUsersList.get(i), rateLimitList.get(i));
consumerInfoList.add(consumerInfo);
}
return consumerInfoList;
}
@Transactional
public void deleteConsumer(String appId) {
Consumer consumer = consumerRepository.findByAppId(appId);
if (consumer == null) {
throw new BadRequestException("ConsumerApp not exist");
}
long consumerId = consumer.getId();
List<ConsumerRole> consumerRoleList = consumerRoleRepository.findByConsumerId(consumerId);
ConsumerToken consumerToken = consumerTokenRepository.findByConsumerId(consumerId);
consumerRoleRepository.deleteAll(consumerRoleList);
consumerRepository.delete(consumer);
if (Objects.nonNull(consumerToken)) {
consumerTokenRepository.delete(consumerToken);
}
}
}
View on GitHub (pinned to d95fc18d11)
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.
Example fix
// before
consumerService.deleteConsumer(appId);
// after
Consumer existing = consumerRepository.findByAppId(appId);
if (existing == null) {
// already deleted or never existed — treat as no-op or return 404
return;
}
consumerService.deleteConsumer(appId); Defensive patterns
Strategy: validation
Validate before calling
// Check consumer existence before deletion (idempotent delete)
Consumer existing = consumerRepository.findByAppId(appId);
if (existing == null) {
log.info("Consumer app {} not found, treating delete as no-op", appId);
return;
}
consumerService.deleteConsumer(appId); Try / catch
try {
consumerService.deleteConsumer(appId);
} catch (BadRequestException e) {
if ("ConsumerApp not exist".equals(e.getMessage())) {
// Idempotent: already deleted, no action needed
return;
}
throw e;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- userIds should not be null or empty
- operator should not be null or empty
- App is null
- AppId is null or blank
- The App Id of path variable and request body is different
AI-assisted analysis of apolloconfig/apollo@d95fc18d11 (2026-08-14).
Data as JSON: /api/errors/a4b04fea3383fa43.
Report an issue: GitHub.