{"record":{"id":"ac32a2abe0a5480a","repo":"AlistGo/alist","slug":"bad-status-code-res-status","errorCode":null,"errorMessage":"bad status code {res.Status()}","messagePattern":"bad status code (.+?)","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"drivers/aliyundrive/util.go","lineNumber":135,"sourceCode":"\t}\n\tif e.Code != \"\" {\n\t\tswitch e.Code {\n\t\tcase \"AccessTokenInvalid\":\n\t\t\terr = d.refreshToken()\n\t\t\tif err != nil {\n\t\t\t\treturn nil, err, e\n\t\t\t}\n\t\tcase \"DeviceSessionSignatureInvalid\":\n\t\t\terr = d.createSession()\n\t\t\tif err != nil {\n\t\t\t\treturn nil, err, e\n\t\t\t}\n\t\tdefault:\n\t\t\treturn nil, errors.New(e.Message), e\n\t\t}\n\t\treturn d.request(url, method, callback, resp)\n\t} else if res.IsError() {\n\t\treturn nil, errors.New(\"bad status code \" + res.Status()), e\n\t}\n\treturn res.Body(), nil, e\n}\n\nfunc (d *AliDrive) getFiles(fileId string) ([]File, error) {\n\tmarker := \"first\"\n\tres := make([]File, 0)\n\tfor marker != \"\" {\n\t\tif marker == \"first\" {\n\t\t\tmarker = \"\"\n\t\t}\n\t\tvar resp Files\n\t\tdata := base.Json{\n\t\t\t\"drive_id\":                d.DriveId,\n\t\t\t\"fields\":                  \"*\",\n\t\t\t\"image_thumbnail_process\": \"image/resize,w_400/format,jpeg\",\n\t\t\t\"image_url_process\":       \"image/resize,w_1920/format,jpeg\",\n\t\t\t\"limit\":                   200,","sourceCodeStart":117,"sourceCodeEnd":153,"githubUrl":"https://github.com/AlistGo/alist/blob/843d9dc8149126976b2625911e45a4d3ffd6f2f5/drivers/aliyundrive/util.go#L117-L153","documentation":"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').","triggerScenarios":"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.","commonSituations":"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.","solutions":["Retry with exponential backoff — gateway 5xx/429 are usually transient","Log the URL and response body alongside the status to identify which endpoint failed and what the body said","Check Aliyun/alipan status pages during clustered failures","If persistent, capture res.RawResponse to confirm whether a middlebox (corporate proxy, CDN) is rewriting responses"],"exampleFix":"// before\nreturn nil, errors.New(\"bad status code \" + res.Status()), e\n\n// after — add endpoint + body for diagnosis\nreturn nil, fmt.Errorf(\"%s %s: bad status code %s, body: %s\", method, url, res.Status(), res.String()), e","handlingStrategy":"retry","validationCode":"null","typeGuard":"// Go\nfunc isBadStatusErr(err error) bool {\n    return err != nil && strings.HasPrefix(err.Error(), \"bad status code\")\n}","tryCatchPattern":"body, err, e := d.request(url, method, cb, resp)\nif isBadStatusErr(err) {\n    if e == nil || e.Code == \"\" { // transport/gateway, not API-level\n        time.Sleep(backoff)\n        return d.request(url, method, cb, resp) // bounded retry\n    }\n}","preventionTips":["Retry only code-less status errors; API-coded errors need specific handling","Add backoff for 429/5xx rather than immediate retries","Log method+URL with the status to attribute gateway blips to endpoints"],"tags":["aliyundrive","http-status","gateway","transient"],"backgroundTag":null,"analyzedSha":"843d9dc8149126976b2625911e45a4d3ffd6f2f5","analyzedAt":"2026-08-15T12:14:11.722Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}