{"record":{"id":"ec33eb0e7e4ac45e","repo":"Tencent/WeKnora","slug":"baidu-api-error-code-d-s","errorCode":null,"errorMessage":"baidu API error (code %d): %s","messagePattern":"baidu API error \\(code (.+?)\\): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/infrastructure/web_search/baidu.go","lineNumber":145,"sourceCode":"\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,\n\t\t\tSource:  \"baidu\",\n\t\t}\n\n\t\tif includeDate && ref.Date != \"\" {\n\t\t\tif t, err := parseBaiduDate(ref.Date); err == nil {\n\t\t\t\tresult.PublishedAt = &t\n\t\t\t}\n\t\t}\n\n\t\tresults = append(results, result)","sourceCodeStart":127,"sourceCodeEnd":163,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/infrastructure/web_search/baidu.go#L127-L163","documentation":"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.","triggerScenarios":"Thrown at internal/infrastructure/web_search/baidu.go:145 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","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"],"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"}