flipped-aurora/gin-vue-admin · error
获取角色当前API权限失败: %w
Error message
获取角色当前API权限失败: %w
What it means
Same read-phase wrap as error 406 but in the batch assigner: fetching the role's current Casbin policies via /casbin/getPolicyPathByAuthorityId failed, so no diff/merge can be computed and the whole batch aborts.
Source
Thrown at server/mcp/role_api_batch_assigner.go:86
if err != nil {
return nil, err
}
items, err := parseAPIItems(args["apis"])
if err != nil {
return nil, err
}
if len(items) == 0 {
return nil, errors.New("apis 参数是必需的,且至少包含一条")
}
if len(items) > orgBatchLimit {
return nil, fmt.Errorf("单次批量授权不能超过 %d 条,收到 %d 条", orgBatchLimit, len(items))
}
currentResp, err := postUpstream[map[string][]systemReq.CasbinInfo](ctx, "/casbin/getPolicyPathByAuthorityId", map[string]any{
"authorityId": authorityID,
})
if err != nil {
return nil, fmt.Errorf("获取角色当前API权限失败: %w", err)
}
updated := currentResp.Data["paths"]
result := roleAPIBatchAssignResponse{Success: true, AuthorityID: authorityID}
anyAdded := false
for _, item := range items {
var added bool
updated, added = appendPolicyIfMissing(updated, item.Path, item.Method)
path, method := normalizePolicy(item.Path, item.Method)
result.Items = append(result.Items, batchAPIItemResult{
Path: path,
Method: method,
Added: added,
AlreadyExists: !added,
})
if added {
result.AddedCount++
anyAdded = trueView on GitHub (pinned to 3136500ef3)
Solutions
- Verify the authorityId exists via a role query tool first
- Inspect the wrapped cause for status/body details
- Check MCP token validity and casbin read permissions
- Retry after confirming backend connectivity
Defensive patterns
Strategy: validation
Validate before calling
if authorityID == 0 {
return errors.New("authorityId is required")
}
if !roleExists(authorityID) {
return fmt.Errorf("authorityId %d does not exist", authorityID)
}
if len(items) == 0 || len(items) > 50 {
return fmt.Errorf("apis must contain 1..50 items, got %d", len(items))
} Try / catch
_, err := batchAssigner.Handle(ctx, args)
if err != nil {
if strings.Contains(err.Error(), "获取角色当前API权限失败") {
// pre-write read failed; verify role and connectivity, then retry
}
return err
} Prevention
- Confirm the role exists before any batch assignment
- Batch requests are read-modify-write: avoid concurrent batch calls for the same role to prevent lost updates
- Keep MCP auth tokens valid; read-phase failures are often 401/403
When it happens
Trigger: Batch Handle calls getPolicyPathByAuthorityId before iterating items; failure occurs on network errors, non-2xx responses for an unknown authorityId, expired MCP auth, or payload that fails to decode into map[string][]systemReq.CasbinInfo.
Common situations: Typo in role authorityId; role deleted before the call; MCP server cannot reach the admin backend; upstream response format drifted from the expected {paths: [...]} shape.
Related errors
AI-assisted analysis of flipped-aurora/gin-vue-admin@3136500ef3 (2026-08-31).
Data as JSON: /api/errors/6d3f144c4fa7f0df.
Report an issue: GitHub.