AlistGo/alist · error

bad status code {res.Status()}

Error message

bad status code {res.Status()}

What it means

Returned by AliDrive.request when the HTTP response is an error status (res.IsError()) but the structured error payload carried no recognized code — i.e. the switch on e.Code matched nothing and the body did not parse into a known error. The error text embeds only the HTTP status string (e.g. 'bad status code 502 Bad Gateway').

Source

Thrown at drivers/aliyundrive/util.go:135

	}
	if e.Code != "" {
		switch e.Code {
		case "AccessTokenInvalid":
			err = d.refreshToken()
			if err != nil {
				return nil, err, e
			}
		case "DeviceSessionSignatureInvalid":
			err = d.createSession()
			if err != nil {
				return nil, err, e
			}
		default:
			return nil, errors.New(e.Message), e
		}
		return d.request(url, method, callback, resp)
	} else if res.IsError() {
		return nil, errors.New("bad status code " + res.Status()), e
	}
	return res.Body(), nil, e
}

func (d *AliDrive) getFiles(fileId string) ([]File, error) {
	marker := "first"
	res := make([]File, 0)
	for marker != "" {
		if marker == "first" {
			marker = ""
		}
		var resp Files
		data := base.Json{
			"drive_id":                d.DriveId,
			"fields":                  "*",
			"image_thumbnail_process": "image/resize,w_400/format,jpeg",
			"image_url_process":       "image/resize,w_1920/format,jpeg",
			"limit":                   200,

View on GitHub (pinned to 843d9dc814)

Solutions

  1. Retry with exponential backoff — gateway 5xx/429 are usually transient
  2. Log the URL and response body alongside the status to identify which endpoint failed and what the body said
  3. Check Aliyun/alipan status pages during clustered failures
  4. If persistent, capture res.RawResponse to confirm whether a middlebox (corporate proxy, CDN) is rewriting responses

Example fix

// before
return nil, errors.New("bad status code " + res.Status()), e

// after — add endpoint + body for diagnosis
return nil, fmt.Errorf("%s %s: bad status code %s, body: %s", method, url, res.Status(), res.String()), e
Defensive patterns

Strategy: retry

Validate before calling

null

Type guard

// Go
func isBadStatusErr(err error) bool {
    return err != nil && strings.HasPrefix(err.Error(), "bad status code")
}

Try / catch

body, err, e := d.request(url, method, cb, resp)
if isBadStatusErr(err) {
    if e == nil || e.Code == "" { // transport/gateway, not API-level
        time.Sleep(backoff)
        return d.request(url, method, cb, resp) // bounded retry
    }
}

Prevention

When it happens

Trigger: Server-side 5xx/429/502/504 from api.alipan.com / open.aliyundrive.com with HTML or non-JSON bodies (gateway errors, maintenance pages), or any non-2xx response where e.Code stayed empty so neither the code switch nor the empty-code path handled it.

Common situations: Aliyun gateway outages or maintenance windows; CDN/proxy interposing error pages; aggressive polling triggering 429 with a plain-text body. The message gives no request context, making logs hard to attribute to a specific endpoint.

Related errors


AI-assisted analysis of AlistGo/alist@843d9dc814 (2026-08-15). Data as JSON: /api/errors/ac32a2abe0a5480a. Report an issue: GitHub.