{"record":{"id":"0f5221055c1f03d6","repo":"siyuan-note/siyuan","slug":"unexpected-status-code-d-0f5221","errorCode":null,"errorMessage":"unexpected status code: %d","messagePattern":"unexpected status code: (.+?)","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/bazaar/index.go","lineNumber":191,"sourceCode":"\t\treturn\n\t}\n\tlegacy, legacyErr := fetchBazaarIndexPath(ctx, bazaarLegacyIndexPath)\n\tif nil != legacyErr {\n\t\treturn nil, fmt.Errorf(\"get current bazaar index failed: %w; get legacy bazaar index failed: %v\", err, legacyErr)\n\t}\n\treturn legacy, nil\n}\n\nfunc fetchBazaarIndexPath(ctx context.Context, indexPath string) (ret *bazaarIndexSnapshot, err error) {\n\ttimeBucket := bazaarIndexNow().Unix() / int64(bazaarIndexCDNBucket/time.Second)\n\tu := fmt.Sprintf(\"%s%s?t=%d\", bazaarIndexStatServer, indexPath, 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\treturn parseBazaarIndex(buf.Bytes())\n}\n\nfunc parseBazaarIndex(data []byte) (ret *bazaarIndexSnapshot, 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\tif nil == raw {\n\t\treturn nil, errors.New(\"invalid null bazaar index\")\n\t}\n\tret = &bazaarIndexSnapshot{\n\t\tpackages:    map[string]*bazaarIndexPackage{},\n\t\tlegacyStats: map[string]*bazaarStats{},\n\t}\n\n\tmetaRaw, hasMeta := raw[\"meta\"]","sourceCodeStart":173,"sourceCodeEnd":209,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/8641553a1f07374001902d3ce773285db1292b2d/kernel/bazaar/index.go#L173-L209","documentation":"fetchBazaarIndexPath performs a GET of the bazaar index from the CDN with retries disabled and requires HTTP 200. Any other status code (403, 404, 5xx, etc.) yields this error containing the actual status. The response body is discarded, so the caller only learns the numeric status.","triggerScenarios":"A GET to <bazaarIndexStatServer><indexPath>?t=<timeBucket> returns a non-200 response: CDN rate limiting (429), auth/WAF blocking (403), removed index file (404), or origin server errors (500/502/503).","commonSituations":"CDN rate limiting after many requests; corporate proxy or firewall intercepting the request with a 403 page; bazaar index temporarily unpublished during a deploy; stale DNS pointing at a server without the index.","solutions":["Note the status code in the message: 429 → back off and retry later; 403/405 → check proxy/firewall and User-Agent handling; 404 → the index path is wrong or temporarily absent; 5xx → wait for the bazaar service to recover","Retry after a delay — the time-bucketed cache-buster URL (t parameter) changes over time and the refresh loop will re-attempt","Verify the index URL manually with curl to distinguish client network issues from server-side problems","If the legacy path also fails, fetchBazaarIndex surfaces the combined error 251; fix whichever path reports the server-side cause"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// pre-check the endpoint reachable with expected status\nresp, err := http.Head(indexURL)\n// proceed only if err == nil && resp.StatusCode == 200","typeGuard":null,"tryCatchPattern":"if err != nil {\n    var statusErr interface{ Error() string }\n    if strings.Contains(err.Error(), \"unexpected status code: 429\") {\n        time.Sleep(backoff) // rate limited: retry later\n    }\n}","preventionTips":["Respect rate limits: the client already disables retries (SetRetryCount(0)); add your own spacing for frequent calls","Check proxies/firewalls that substitute non-200 responses (captive portals) for the bazaar host","Differentiate by status code before deciding to retry: 5xx/429 retry, 404 investigate the path, 403 fix access"],"tags":["network","http","marketplace"],"backgroundTag":"http-non-200-response","analyzedSha":"8641553a1f07374001902d3ce773285db1292b2d","analyzedAt":"2026-09-11T16:08:28.414Z","contentChangedAt":"2026-09-11T16:08:28.414Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}