apolloconfig/apollo · warning · BadRequestException
Params(NamespaceName) can not be empty.
Error message
Params(NamespaceName) can not be empty.
What it means
BadRequestException (HTTP 400) from the same assign-role handler, reached only on the namespace-role branch (type != 'AppRole'). After appId is confirmed non-empty and the AppRole branch is skipped, it requires namespaceName on the NamespaceDTO body to be non-empty via StringUtils.isEmpty.
Source
Thrown at apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/ConsumerController.java:149
@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);
}
envList.add(env);
}
List<ConsumerRole> consumeRoles = new ArrayList<>();
for (String env : envList) {
consumeRoles.addAll(consumerService.assignNamespaceRoleToConsumer(token, appId,View on GitHub (pinned to d95fc18d11)
Solutions
- Set namespace.setNamespaceName(<namespace>) in the body.
- If you actually want the app-level role, send type='AppRole' (the appId-only path).
- Validate that namespaceName is non-empty for the namespace branch (see validationCode).
- When envs are provided, ensure a namespaceName is also present per env.
Example fix
// before
POST /consumers/{token}/assign-role?type=NAMESPACE
body: { "appId": "sample-app" } // namespaceName missing -> 400
// after
body: { "appId": "sample-app", "namespaceName": "application" } Defensive patterns
Strategy: validation
Validate before calling
// For the namespace-role branch (type != AppRole), namespaceName is required.
if (!"AppRole".equals(type)) {
String ns = namespaceDto.getNamespaceName();
if (ns == null || ns.trim().isEmpty()) {
throw new IllegalArgumentException("namespaceName is required for namespace roles");
}
} Type guard
static boolean hasNamespaceName(NamespaceDTO dto) {
return dto != null && dto.getNamespaceName() != null
&& !dto.getNamespaceName().trim().isEmpty();
} Prevention
- For app-level roles, send type='AppRole' to skip the namespaceName requirement.
- For namespace/env roles, always set namespaceName.
- Validate with the type guard before submit.
- Make the UI require namespaceName unless AppRole is selected.
When it happens
Trigger: POST /consumers/{token}/assign-role?type=<not AppRole> with a body whose namespaceName is null/empty, or when envs selects namespace-scoped roles but the namespace is unnamed.
Common situations: Assigning env-specific namespace roles but forgetting the namespace name; client defaulting type to 'Namespace' without the name; misusing the AppRole shortcut without setting type='AppRole'.
Related errors
- Namespace's role does not exist. Please check whether namesp
- Params(NamespaceName) can not be empty.
- Params(AppId) can not be empty.
- Public appNamespace not exists. NamespaceName = %s
- operator should not be null or empty
AI-assisted analysis of apolloconfig/apollo@d95fc18d11 (2026-08-14).
Data as JSON: /api/errors/4e68428661e99370.
Report an issue: GitHub.