glanceapp/glance · error

expected status code %d, got %d

Error message

expected status code %d, got %d

What it means

Returned by the diagnose() helper when an HTTP response's status code does not match the expected code for that check. This runs during glance's built-in diagnostics (e.g. after startup) when probing endpoints such as the server's own health/config URLs, and the returned error carries the expected vs actual status plus a truncated body snippet for context.

Source

Thrown at internal/glance/diagnose.go:192

	defer response.Body.Close()

	body, err := io.ReadAll(response.Body)
	if err != nil {
		return "", err
	}

	printableBody := strings.ReplaceAll(string(body), "\n", "")
	if len(printableBody) > 50 {
		printableBody = printableBody[:50] + "..."
	}
	if len(printableBody) > 0 {
		printableBody = ", " + printableBody
	}

	extraInfo := fmt.Sprintf("%d bytes%s", len(body), printableBody)

	if response.StatusCode != expectedStatusCode {
		return extraInfo, fmt.Errorf("expected status code %d, got %d", expectedStatusCode, response.StatusCode)
	}

	return extraInfo, nil
}

func testDNSResolution(domain string) (string, error) {
	ips, err := net.LookupIP(domain)

	var ipStrings []string
	if err == nil {
		for i := range ips {
			ipStrings = append(ipStrings, ips[i].String())
		}
	}

	return strings.Join(ipStrings, ", "), err
}

View on GitHub (pinned to 91324e8de7)

Solutions

  1. Check the response body snippet in the error output to identify what actually answered
  2. Verify the reverse proxy route and port forwarding map to the glance port
  3. If auth is enabled, confirm the diagnostic request carries the required credentials/cookie or that the checked path is exempted
  4. Ensure nothing else is bound to the configured port (`ss -ltnp | grep <port>`)
Defensive patterns

Strategy: retry

Try / catch

In Go: `if err != nil && strings.Contains(err.Error(), "expected status code") { log.Printf("diag probe failed: %v (body hint included)", err) }` then retry with backoff once — proxies often return transient 502.

Prevention

When it happens

Trigger: An HTTP probe with a hardcoded expected status (200, 401, etc.) receives a different code: server behind a reverse proxy returning 502/404, auth enabled so a public check gets 401, port conflict causing a wrong service to answer, or an internal route returning 500 due to a render error.

Common situations: Running glance behind nginx/traefik with a misrouted location; enabling auth so diagnostic GETs get redirected; container port mapping off by one; another process already listening on the same port.

Related errors


AI-assisted analysis of glanceapp/glance@91324e8de7 (2026-08-15). Data as JSON: /api/errors/99ec08c50c5be36d. Report an issue: GitHub.