{"record":{"id":"9d3c9455d66e89f6","repo":"Tencent/WeKnora","slug":"bing-api-returned-status-d-s","errorCode":null,"errorMessage":"bing API returned status %d: %s","messagePattern":"bing API returned status (.+?): (.+?)","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/infrastructure/web_search/bing.go","lineNumber":111,"sourceCode":"\tlogger.Infof(ctx, \"[WebSearch][Bing] returned %d results\", len(results))\n\treturn results, nil\n}\n\nfunc (p *BingProvider) doSearch(ctx context.Context, req *http.Request) ([]*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(resp.Body)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tif resp.StatusCode != http.StatusOK {\n\t\tlogger.Warnf(ctx, \"[WebSearch][Bing] API returned status %d: %s\", resp.StatusCode, string(body))\n\t\treturn nil, fmt.Errorf(\"bing API returned status %d: %s\", resp.StatusCode, string(body))\n\t}\n\n\tvar respData bingSearchResponse\n\tif err := json.Unmarshal(body, &respData); err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to unmarshal response: %w\", err)\n\t}\n\tresults := make([]*types.WebSearchResult, 0, len(respData.WebPages.Value))\n\tfor _, item := range respData.WebPages.Value {\n\t\tresults = append(results, &types.WebSearchResult{\n\t\t\tTitle:       item.Name,\n\t\t\tURL:         item.URL,\n\t\t\tSnippet:     item.Snippet,\n\t\t\tSource:      \"bing\",\n\t\t\tPublishedAt: &item.DateLastCrawled,\n\t\t})\n\t}\n\treturn results, nil\n}","sourceCodeStart":93,"sourceCodeEnd":129,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/infrastructure/web_search/bing.go#L93-L129","documentation":"The Bing API responded with a non-200 HTTP status; the provider surfaces the status code plus the response body. This is an upstream Bing Web Search API failure (auth, quota, bad params, or service issue) translated into a Go error by doSearch.","triggerScenarios":"Bing returns 401 (invalid Ocp-Apim-Subscription-Key), 403 (no entitlement), 429 (rate limit exceeded), 400 (bad parameters), or 5xx during a Search call.","commonSituations":"Expired or wrong Azure Cognitive Services key; exhausted monthly Bing API quota; deprecated/retired Bing Search v7 resource; regional endpoint mismatch in baseURL.","solutions":["Read the status code and body in the error message: 401/403 -> verify the Azure subscription key and Bing Search resource entitlement.","429 -> back off and retry later, or upgrade the pricing tier.","400 -> check query length, count parameter, and market/language params against the Bing API docs.","5xx -> retry with exponential backoff; check Azure status page.","Note Bing Search v7 was retired (Aug 2025); migrate to an alternative provider if the resource no longer exists."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// preflight: verify key is configured and non-empty\nif strings.TrimSpace(bingAPIKey) == \"\" {\n    return errors.New(\"missing BING_API_KEY\")\n}","typeGuard":"type HTTPStatusError interface{ error; StatusCode() int }\nfunc asStatusErr(err error) (int, bool) {\n    var se HTTPStatusError\n    if errors.As(err, &se) { return se.StatusCode(), true }\n    return 0, false\n}","tryCatchPattern":"results, err := provider.Search(ctx, query, 10, false)\nif err != nil {\n    if strings.Contains(err.Error(), \"status 429\") || strings.Contains(err.Error(), \"status 5\") {\n        // exponential backoff retry\n    } else if strings.Contains(err.Error(), \"status 401\") || strings.Contains(err.Error(), \"status 403\") {\n        // fatal: fix credentials/entitlement, do not retry\n    }\n}","preventionTips":["Rotate/verify the Azure Bing subscription key before deployment.","Monitor quota usage and set alerts before hitting rate limits.","Pin and periodically re-validate the Bing endpoint version (v7 retirement).","Implement backoff on 429/5xx only; fail fast on 401/403."],"tags":["http","api","web-search","azure","go"],"backgroundTag":"http-non-200-response","analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}