AlistGo/alist · error

http request [%s] failure,status: %d response:%s

Error message

http request [%s] failure,status: %d response:%s

What it means

Returned by the HTTP request helper in internal/net/serve.go when the response status is not a success code. It reads (and optionally gunzips) the body, closes it, logs the body, and returns the response together with an error carrying the URL, status code, and body text — so the caller can inspect res while still treating the call as failed.

Source

Thrown at internal/net/serve.go:259

	// TODO clean header with blocklist or passlist
	res.Header.Del("set-cookie")
	var reader io.Reader
	if res.StatusCode >= 400 {
		// 根据 Content-Encoding 判断 Body 是否压缩
		switch res.Header.Get("Content-Encoding") {
		case "gzip":
			// 使用gzip.NewReader解压缩
			reader, _ = gzip.NewReader(res.Body)
			defer reader.(*gzip.Reader).Close()
		default:
			// 没有Content-Encoding,直接读取
			reader = res.Body
		}
		all, _ := io.ReadAll(reader)
		_ = res.Body.Close()
		msg := string(all)
		log.Debugln(msg)
		return res, fmt.Errorf("http request [%s] failure,status: %d response:%s", URL, res.StatusCode, msg)
	}
	return res, nil
}

var once sync.Once
var httpClient *http.Client

func HttpClient() *http.Client {
	once.Do(func() {
		httpClient = NewHttpClient()
		httpClient.CheckRedirect = func(req *http.Request, via []*http.Request) error {
			if len(via) >= 10 {
				return errors.New("stopped after 10 redirects")
			}
			req.Header.Del("Referer")
			return nil
		}
	})

View on GitHub (pinned to 843d9dc814)

Solutions

  1. Read the status code and response body from the error message (or the returned res) to identify the true cause.
  2. For 401/403, refresh credentials/tokens or re-sign the URL.
  3. For 404, verify the URL path and that the resource still exists.
  4. For 5xx, retry with backoff or check upstream health.
Defensive patterns

Strategy: try-catch

Try / catch

res, err := HttpRequest(...)
if err != nil {
    if res != nil {
        switch res.StatusCode {
        case 401, 403: // refresh credentials and retry once
        case 429, 502, 503, 504: // backoff and retry
        default: // permanent, surface body
        }
    }
}

Prevention

When it happens

Trigger: Any request through this helper receiving a non-2xx status: 401/403 auth failures, 404, 5xx from the remote; error body (JSON or HTML) is embedded in the message.

Common situations: Expired pre-signed URLs or tokens (403); wrong API credentials (401); remote endpoint moved (404); upstream outages (5xx); CDN error pages making the message long/noisy.

Related errors


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