{"record":{"id":"21670243b79c643b","repo":"siyuan-note/siyuan","slug":"unexpected-status-code-d-216702","errorCode":null,"errorMessage":"unexpected status code: %d","messagePattern":"unexpected status code: (.+?)","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/bazaar/rating.go","lineNumber":420,"sourceCode":"\t\t}\n\t}\n\treturn\n}\n\nfunc fetchBazaarRatingRegion(ctx context.Context, region int) (ret map[string]bazaarRatingDistribution, err error) {\n\tif region < 0 || bazaarRatingRegionCount <= region {\n\t\treturn nil, errors.New(\"invalid bazaar rating region\")\n\t}\n\n\ttimeBucket := bazaarRatingNow().Unix() / int64(bazaarRatingCDNBucket/time.Second)\n\tu := fmt.Sprintf(\"%s/bazaar/ratings/v1/%s?t=%d\", bazaarRatingStatServer, bazaarRatingRegionFiles[region], timeBucket)\n\tbuf := &bytes.Buffer{}\n\tresp, err := httpclient.NewBrowserRequest().SetRetryCount(0).SetContext(ctx).SetOutput(buf).Get(u)\n\tif nil != err {\n\t\treturn nil, err\n\t}\n\tif 200 != resp.StatusCode {\n\t\treturn nil, fmt.Errorf(\"unexpected status code: %d\", resp.StatusCode)\n\t}\n\n\tret, err = parseBazaarRatingRegion(buf.Bytes())\n\treturn\n}\n\nfunc parseBazaarRatingRegion(data []byte) (ret map[string]bazaarRatingDistribution, err error) {\n\traw := map[string]json.RawMessage{}\n\tif err = json.Unmarshal(data, &raw); nil != err {\n\t\treturn nil, err\n\t}\n\tret = make(map[string]bazaarRatingDistribution, len(raw))\n\tfor packageName, rawDistribution := range raw {\n\t\tif !IsValidPackageName(packageName) {\n\t\t\treturn nil, fmt.Errorf(\"invalid package name: %s\", packageName)\n\t\t}\n\t\tvar values []int64\n\t\tif err = json.Unmarshal(rawDistribution, &values); nil != err {","sourceCodeStart":402,"sourceCodeEnd":438,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/8641553a1f07374001902d3ce773285db1292b2d/kernel/bazaar/rating.go#L402-L438","documentation":"fetchBazaarRatingRegion downloads a bazaar package rating-distribution JSON from the marketplace endpoint. It returns this error when the HTTP response status is anything other than 200. It is the function's generic guard against unexpected server responses, so the message only carries the numeric status code.","triggerScenarios":"Calling fetchBazaarRatingRegion (directly or via tests) when the marketplace server responds with a non-200 status: 404 for a bad URL/path, 403/429 for rate limiting, 5xx during server incidents, or 301/302 if redirects are not followed.","commonSituations":"Marketplace CDN outage or maintenance; the rating endpoint URL changed; the client IP is rate-limited or blocked; a proxy/firewall rewrites the response; offline or captive-network environments returning an HTML error page with a non-200 code.","solutions":["Check the status code in the message and hit the same rating URL manually with curl to see the response body for the real cause","Retry later if the status is 5xx or 429 (server-side/rate-limit issue)","Verify network/proxy configuration allows access to the bazaar endpoint","Check whether the bazaar endpoint URL in the code is outdated and update it"],"exampleFix":"// before\nresp, err := httpclient.NewBrowserRequest().SetRetryCount(0).SetContext(ctx).SetOutput(buf).Get(u)\n// after (tolerate transient failures)\nresp, err := httpclient.NewBrowserRequest().SetRetryCount(3).SetContext(ctx).SetOutput(buf).Get(u)\nif err == nil && 200 != resp.StatusCode {\n    return nil, fmt.Errorf(\"unexpected status code: %d\", resp.StatusCode)\n}","handlingStrategy":"retry","validationCode":"resp, err := httpclient.NewBrowserRequest().SetRetryCount(0).Get(u)\nif err == nil && resp.StatusCode != 200 {\n    // surface resp.StatusCode/resp.Body before calling fetchBazaarRatingRegion\n}","typeGuard":null,"tryCatchPattern":"dist, err := fetchBazaarRatingRegion(ctx)\nif err != nil {\n    if strings.Contains(err.Error(), \"unexpected status code\") {\n        // log status, retry with backoff or fall back to cached ratings\n    }\n}","preventionTips":["Retry transient non-200 responses with a small backoff","Monitor the bazaar endpoint health before bulk rating fetches","Cache the last successful rating payload as a fallback"],"tags":["network","http","bazaar"],"backgroundTag":"unexpected-http-status","analyzedSha":"8641553a1f07374001902d3ce773285db1292b2d","analyzedAt":"2026-09-11T16:08:28.414Z","contentChangedAt":"2026-09-11T16:08:28.414Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}