Tencent/WeKnora · error
baidu API error (code %d): %s
Error message
baidu API error (code %d): %s
What it means
Returned by doSearch when Baidu responds with HTTP 200 but the payload carries a non-zero error code — an API-level failure such as invalid parameters, auth quota, or service degradation, surfaced inside a successful HTTP response.
Source
Thrown at internal/infrastructure/web_search/baidu.go:145
body, err := io.ReadAll(io.LimitReader(resp.Body, 2<<20)) // 2MB limit
if err != nil {
return nil, err
}
if resp.StatusCode != http.StatusOK {
logger.Warnf(ctx, "[WebSearch][Baidu] API returned status %d: %s", resp.StatusCode, string(body))
return nil, fmt.Errorf("baidu API returned status %d: %s", resp.StatusCode, string(body))
}
var respData baiduSearchResponse
if err := json.Unmarshal(body, &respData); err != nil {
return nil, fmt.Errorf("failed to unmarshal response: %w", err)
}
// Check for API-level error (returned with 200 status)
if respData.Code != 0 {
return nil, fmt.Errorf("baidu API error (code %d): %s", respData.Code, respData.Message)
}
results := make([]*types.WebSearchResult, 0, len(respData.References))
for _, ref := range respData.References {
result := &types.WebSearchResult{
Title: ref.Title,
URL: ref.URL,
Content: ref.Content,
Source: "baidu",
}
if includeDate && ref.Date != "" {
if t, err := parseBaiduDate(ref.Date); err == nil {
result.PublishedAt = &t
}
}
results = append(results, result)View on GitHub (pinned to 988cbb0330)
Solutions
- Map the returned code to Baidu's error-code documentation
- Fix request parameters if the code indicates invalid input
- Rotate the API key if the code indicates auth failure
- Back off and retry if the code indicates throttling or server issues
Defensive patterns
Strategy: retry
When it happens
Trigger: Thrown at internal/infrastructure/web_search/baidu.go:145 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of Tencent/WeKnora@988cbb0330 (2026-09-02).
Data as JSON: /api/errors/ec33eb0e7e4ac45e.
Report an issue: GitHub.