{"record":{"id":"d4eb731f1ccab949","repo":"v2rayA/v2rayA","slug":"response-status-error-d","errorCode":null,"errorMessage":"response status error:%d","messagePattern":"response status error:(.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"service/pkg/util/gopeed/down.go","lineNumber":42,"sourceCode":"\tDown(request *http.Request, filename string) error\n}\n\n// Resolve return the file response to be downloaded\nfunc Resolve(request *Request) (*Response, error) {\n\thttpRequest, err := BuildHTTPRequest(request)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\t// Use \"Range\" header to resolve\n\thttpRequest.Header.Add(\"Range\", \"bytes=0-0\")\n\thttpClient := BuildHTTPClient()\n\tresponse, err := httpClient.Do(httpRequest)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tdefer response.Body.Close()\n\tif response.StatusCode != 200 && response.StatusCode != 206 {\n\t\treturn nil, fmt.Errorf(\"response status error:%d\", response.StatusCode)\n\t}\n\tret := &Response{}\n\t// Get file name by \"Content-Disposition\"\n\tcontentDisposition := response.Header.Get(\"Content-Disposition\")\n\tif contentDisposition != \"\" {\n\t\t_, params, _ := mime.ParseMediaType(contentDisposition)\n\t\tfilename := params[\"filename\"]\n\t\tif filename != \"\" {\n\t\t\tret.Name = filename\n\t\t}\n\t}\n\t// Get file name by URL\n\tif ret.Name == \"\" {\n\t\tparse, err := url.Parse(httpRequest.URL.String())\n\t\tif err == nil {\n\t\t\t// e.g. /files/test.txt => test.txt\n\t\t\tret.Name = subLastSlash(parse.Path)\n\t\t}","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/v2rayA/v2rayA/blob/71e5442fc548c05680ee55eae943e6c0afe9ac51/service/pkg/util/gopeed/down.go#L24-L60","documentation":"gopeed's Resolve probes the download URL with a 'Range: bytes=0-0' request and requires HTTP 200 or 206 to extract file name, size, and range support. Any other status (403, 404, 302 handled poorly, 5xx, etc.) aborts with 'response status error:<code>'. It signals the server refused or could not serve the resource for probing.","triggerScenarios":"Calling gopeed.Resolve (or Down, which calls it) on an http.Request whose response status is neither 200 nor 206 — e.g. expired/protected download link, missing auth headers/cookies, wrong URL, server not supporting the probe.","commonSituations":"Downloading core updates where the asset URL changed or was removed (404); GitHub/CDN rate limiting (403/429); hotlink protection requiring Referer; authenticated downloads without credentials; server errors during outage (5xx).","solutions":["Log/inspect the embedded status code and handle it: refresh the URL for 404, add auth for 401/403, back off for 429/5xx","Add required headers (User-Agent, Referer, Authorization, cookies) to the request before calling Resolve","Retry with exponential backoff for transient 5xx/429 responses","Verify the download URL is current; use the redirect target if the link moved"],"exampleFix":"// before\n_, err := gopeed.Resolve(req)\nif err != nil { return err }\n// after\nresp, err := gopeed.Resolve(req)\nif err != nil {\n\tif strings.Contains(err.Error(), \"status error:4\") {\n\t\treturn fmt.Errorf(\"download link invalid or forbidden: %w\", err)\n\t}\n\treturn retryable(err) // backoff for 5xx/429\n}","handlingStrategy":"retry","validationCode":"probe, _ := http.Head(downloadURL)\nif probe != nil && probe.StatusCode >= 400 {\n\t// refresh URL / add auth before calling gopeed\n}\n","typeGuard":null,"tryCatchPattern":"resp, err := gopeed.Resolve(req)\nif err != nil {\n\tif m := statusRe.FindStringSubmatch(err.Error()); m != nil {\n\t\tcode, _ := strconv.Atoi(m[1])\n\t\tif code == 429 || code >= 500 {\n\t\t\treturn backoffRetry(req)\n\t\t}\n\t\treturn fmt.Errorf(\"unrecoverable download failure (HTTP %d)\", code)\n\t}\n\treturn err\n}","preventionTips":["Pre-flight HEAD/GET the URL and handle 3xx/4xx before downloading","Attach required User-Agent/Referer/auth headers","Refresh asset URLs from the source metadata on 404","Back off on 429/5xx instead of hard-failing"],"tags":["go","http","download","http-status"],"backgroundTag":"download-http-error-status","analyzedSha":"71e5442fc548c05680ee55eae943e6c0afe9ac51","analyzedAt":"2026-09-05T20:04:37.459Z","contentChangedAt":"2026-09-05T20:04:37.459Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}