siyuan-note/siyuan · error

unexpected status code: %d

Error message

unexpected status code: %d

What it means

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.

Source

Thrown at kernel/bazaar/rating.go:420

		}
	}
	return
}

func fetchBazaarRatingRegion(ctx context.Context, region int) (ret map[string]bazaarRatingDistribution, err error) {
	if region < 0 || bazaarRatingRegionCount <= region {
		return nil, errors.New("invalid bazaar rating region")
	}

	timeBucket := bazaarRatingNow().Unix() / int64(bazaarRatingCDNBucket/time.Second)
	u := fmt.Sprintf("%s/bazaar/ratings/v1/%s?t=%d", bazaarRatingStatServer, bazaarRatingRegionFiles[region], timeBucket)
	buf := &bytes.Buffer{}
	resp, err := httpclient.NewBrowserRequest().SetRetryCount(0).SetContext(ctx).SetOutput(buf).Get(u)
	if nil != err {
		return nil, err
	}
	if 200 != resp.StatusCode {
		return nil, fmt.Errorf("unexpected status code: %d", resp.StatusCode)
	}

	ret, err = parseBazaarRatingRegion(buf.Bytes())
	return
}

func parseBazaarRatingRegion(data []byte) (ret map[string]bazaarRatingDistribution, err error) {
	raw := map[string]json.RawMessage{}
	if err = json.Unmarshal(data, &raw); nil != err {
		return nil, err
	}
	ret = make(map[string]bazaarRatingDistribution, len(raw))
	for packageName, rawDistribution := range raw {
		if !IsValidPackageName(packageName) {
			return nil, fmt.Errorf("invalid package name: %s", packageName)
		}
		var values []int64
		if err = json.Unmarshal(rawDistribution, &values); nil != err {

View on GitHub (pinned to 8641553a1f)

Solutions

  1. 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
  2. Retry later if the status is 5xx or 429 (server-side/rate-limit issue)
  3. Verify network/proxy configuration allows access to the bazaar endpoint
  4. Check whether the bazaar endpoint URL in the code is outdated and update it

Example fix

// before
resp, err := httpclient.NewBrowserRequest().SetRetryCount(0).SetContext(ctx).SetOutput(buf).Get(u)
// after (tolerate transient failures)
resp, err := httpclient.NewBrowserRequest().SetRetryCount(3).SetContext(ctx).SetOutput(buf).Get(u)
if err == nil && 200 != resp.StatusCode {
    return nil, fmt.Errorf("unexpected status code: %d", resp.StatusCode)
}
Defensive patterns

Strategy: retry

Validate before calling

resp, err := httpclient.NewBrowserRequest().SetRetryCount(0).Get(u)
if err == nil && resp.StatusCode != 200 {
    // surface resp.StatusCode/resp.Body before calling fetchBazaarRatingRegion
}

Try / catch

dist, err := fetchBazaarRatingRegion(ctx)
if err != nil {
    if strings.Contains(err.Error(), "unexpected status code") {
        // log status, retry with backoff or fall back to cached ratings
    }
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of siyuan-note/siyuan@8641553a1f (2026-09-11). Data as JSON: /api/errors/21670243b79c643b. Report an issue: GitHub.