{"record":{"id":"892b4ef3f3eb5425","repo":"Tencent/WeKnora","slug":"baidu-api-returned-status-d-s","errorCode":null,"errorMessage":"baidu API returned status %d: %s","messagePattern":"baidu API returned status (.+?): (.+?)","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/infrastructure/web_search/baidu.go","lineNumber":135,"sourceCode":"\n\treturn req, nil\n}\n\nfunc (p *BaiduProvider) doSearch(ctx context.Context, req *http.Request, includeDate bool) ([]*types.WebSearchResult, error) {\n\tresp, err := p.client.Do(req)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tdefer resp.Body.Close()\n\n\tbody, err := io.ReadAll(io.LimitReader(resp.Body, 2<<20)) // 2MB limit\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tif resp.StatusCode != http.StatusOK {\n\t\tlogger.Warnf(ctx, \"[WebSearch][Baidu] API returned status %d: %s\", resp.StatusCode, string(body))\n\t\treturn nil, fmt.Errorf(\"baidu API returned status %d: %s\", resp.StatusCode, string(body))\n\t}\n\n\tvar respData baiduSearchResponse\n\tif err := json.Unmarshal(body, &respData); err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to unmarshal response: %w\", err)\n\t}\n\n\t// Check for API-level error (returned with 200 status)\n\tif respData.Code != 0 {\n\t\treturn nil, fmt.Errorf(\"baidu API error (code %d): %s\", respData.Code, respData.Message)\n\t}\n\n\tresults := make([]*types.WebSearchResult, 0, len(respData.References))\n\tfor _, ref := range respData.References {\n\t\tresult := &types.WebSearchResult{\n\t\t\tTitle:   ref.Title,\n\t\t\tURL:     ref.URL,\n\t\t\tContent: ref.Content,","sourceCodeStart":117,"sourceCodeEnd":153,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/infrastructure/web_search/baidu.go#L117-L153","documentation":"Returned by doSearch when the Baidu API responds with a non-200 status; the response body (up to 2MB read limit) is embedded in the message. Typically invalid/expired API key (401), quota exhausted (429), or Baidu-side errors (5xx).","triggerScenarios":"Thrown at internal/infrastructure/web_search/baidu.go:135 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Read the embedded body for Baidu's error detail","On 401 verify/rotate the API key","On 429 apply backoff and reduce request rate","On 5xx retry with backoff"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}