RayWangQvQ/BiliBiliToolPro · error · Exception
未配置白虎API Token
Error message
未配置白虎API Token
What it means
Thrown by SaveCookieToBaihuAsync when the configured Baihu API Token is null or empty. The Baihu integration requires a bearer token to manage environment variables, so without it the cookie cannot be saved and a plain Exception is thrown (note: not a Bili* exception type).
Solutions
- Configure the Baihu API token in the Baihu options section (appsettings.json or environment variable) before enabling cookie saving.
- Verify the configuration binding key matches the baihuOptions registration.
- If you don't use Baihu, disable the SaveCookieToBaihu task instead of running it unconfigured.
- Ensure the token starts with 'Bearer ' or let the code prefix it (it handles both).
Example fix
// appsettings.json
// before
"Baihu": {}
// after
"Baihu": {
"Token": "Bearer eyJhbGciOi..."
} Defensive patterns
Strategy: validation
Validate before calling
// before enabling the Baihu save-cookie task
var token = baihuOptions.Value.Token;
if (string.IsNullOrWhiteSpace(token))
throw new Exception("启用白虎保存Cookie前必须配置 Baihu:Token"); Type guard
bool IsBaihuConfigured(BaihuOptions o) => !string.IsNullOrWhiteSpace(o.Token);
Try / catch
try
{
await loginDomainService.SaveCookieToBaihuAsync(ck);
}
catch (Exception ex) when (ex.Message.Contains("未配置白虎API Token"))
{
logger.LogError("请先在配置中设置 Baihu:Token 再运行白虎同步");
} Prevention
- Set the Baihu token in configuration before enabling the Baihu task.
- Verify the config section name matches the baihuOptions binding.
- Disable the Baihu task entirely if you don't use Baihu.
When it happens
Trigger: baihuOptions.Value.Token is null/empty — the BaihuToken configuration section/option was never set in appsettings, environment variables, or the DI configuration.
Common situations: User enabled the Baihu save-cookie feature but forgot to configure the token; token bound under the wrong config key; environment variable not propagated into the container.
Understand the failure class
Background: "is required", "must be set", "missing required field": configuration validation errors across open-source libraries — this error's family across 36 libraries.
Related errors
- 获取青龙token失败
- 查询白虎环境变量失败:
- Unable to get SqliteConfigurationProvider
- IConfigurationRoot not available — cannot access Providers…
- SqliteConfigurationProvider not found
AI-assisted analysis of RayWangQvQ/BiliBiliToolPro@c599b2c0da (2026-09-12).
Data as JSON: /api/errors/c486c63d2b82ba59.
Report an issue: GitHub.
Appendix: source
Thrown at src/Ray.BiliBiliTool.DomainService/LoginDomainService.cs:410
return new QrLoginCheckResult
{
Status = QrLoginStatus.Waiting,
Message = content.Data.Message,
};
}
public async Task<bool> SaveCookieToBaihuAsync(
BiliCookie ckInfo,
CancellationToken cancellationToken
)
{
try
{
var token = baihuOptions.Value.Token;
if (string.IsNullOrEmpty(token))
{
throw new Exception("未配置白虎API Token");
}
if (!token.StartsWith("Bearer ", StringComparison.OrdinalIgnoreCase))
{
token = $"Bearer {token}";
}
var envListRe = await baihuApi.GetEnvsAsync(token);
if (envListRe.Code != 200)
{
throw new Exception($"查询白虎环境变量失败:{envListRe.Msg}");
}
var list = envListRe
.Data.Where(x => x.Name.StartsWith("Ray_BiliBiliCookies__"))
.ToList();
var oldEnv = list.FirstOrDefault(x => x.Value.Contains(ckInfo.UserId));
View on GitHub (pinned to c599b2c0da)