apolloconfig/apollo · warning · BadRequestException
Params(AppId) can not be empty.
Error message
Params(AppId) can not be empty.
What it means
BadRequestException (HTTP 400) from ConsumerController.assignNamespaceRoleToConsumer (POST /consumers/{token}/assign-role). It reads appId from the NamespaceDTO body and rejects the request if appId is null or empty (StringUtils.isEmpty). This check runs before any role assignment, and before the namespaceName check, for the namespace-role branch.
Source
Thrown at apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/ConsumerController.java:142
@PreAuthorize(value = "@unifiedPermissionValidator.isSuperAdmin()")
@GetMapping(value = "/consumer/info/by-appId")
public ConsumerInfo getConsumerInfoByAppId(@RequestParam String appId) {
return consumerService.getConsumerInfoByAppId(appId);
}
@PreAuthorize(value = "@unifiedPermissionValidator.isSuperAdmin()")
@PostMapping(value = "/consumers/{token}/assign-role")
public List<ConsumerRole> assignNamespaceRoleToConsumer(@PathVariable String token,
@RequestParam String type, @RequestParam(required = false) String envs,
@RequestBody NamespaceDTO namespace) {
List<ConsumerRole> consumerRoleList = new ArrayList<>(8);
String appId = namespace.getAppId();
String namespaceName = namespace.getNamespaceName();
if (StringUtils.isEmpty(appId)) {
throw new BadRequestException("Params(AppId) can not be empty.");
}
if (Objects.equals("AppRole", type)) {
return Collections.singletonList(consumerService.assignAppRoleToConsumer(token, appId,
userInfoHolder.getUser().getUserId()));
}
if (StringUtils.isEmpty(namespaceName)) {
throw new BadRequestException("Params(NamespaceName) can not be empty.");
}
if (null != envs) {
String[] envArray = envs.split(",");
List<String> envList = Lists.newArrayList();
// validate env parameter
for (String env : envArray) {
if (Strings.isNullOrEmpty(env)) {
continue;
}
if (Env.UNKNOWN.equals(Env.transformEnv(env))) {
throw BadRequestException.invalidEnvFormat(env);View on GitHub (pinned to d95fc18d11)
Solutions
- Populate namespace.setAppId(<existing app id>) in the body before posting.
- Confirm the app exists before assigning a consumer token to it.
- Run the emptiness check client-side (see validationCode).
- If type='AppRole', note appId is still required before the AppRole branch.
Example fix
// before
POST /consumers/{token}/assign-role?type=NAMESPACE
body: { "namespaceName": "application" } // appId missing -> 400
// after
body: { "appId": "sample-app", "namespaceName": "application" } Defensive patterns
Strategy: validation
Validate before calling
// Require appId on the NamespaceDTO before assign-role.
String appId = namespaceDto.getAppId();
if (appId == null || appId.trim().isEmpty()) {
throw new IllegalArgumentException("appId is required");
}
// namespaceDto.setAppId(<existing app id>) then POST Type guard
static boolean hasAppId(NamespaceDTO dto) {
return dto != null && dto.getAppId() != null && !dto.getAppId().trim().isEmpty();
} Prevention
- Always populate appId from a loaded, existing app.
- Validate the body before submit using the type guard.
- Confirm the app exists before assigning consumer roles.
- Reuse the same DTO field name ('appId') the server expects.
When it happens
Trigger: POST /consumers/{token}/assign-role with a NamespaceDTO body whose appId is null, empty, or whitespace-only.
Common situations: Client built the body from a namespace that was not loaded; frontend form submitting before appId was selected; JSON using the wrong field name so appId is never populated.
Related errors
- Params(NamespaceName) can not be empty.
- Namespace's role does not exist. Please check whether namesp
- operator should not be null or empty
- Params(AppId) can not be empty.
- Params(NamespaceName) can not be empty.
AI-assisted analysis of apolloconfig/apollo@d95fc18d11 (2026-08-14).
Data as JSON: /api/errors/d4342f0572642196.
Report an issue: GitHub.