{"record":{"id":"99ec08c50c5be36d","repo":"glanceapp/glance","slug":"expected-status-code-d-got-d","errorCode":null,"errorMessage":"expected status code %d, got %d","messagePattern":"expected status code (.+?), got (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/glance/diagnose.go","lineNumber":192,"sourceCode":"\tdefer response.Body.Close()\n\n\tbody, err := io.ReadAll(response.Body)\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\n\tprintableBody := strings.ReplaceAll(string(body), \"\\n\", \"\")\n\tif len(printableBody) > 50 {\n\t\tprintableBody = printableBody[:50] + \"...\"\n\t}\n\tif len(printableBody) > 0 {\n\t\tprintableBody = \", \" + printableBody\n\t}\n\n\textraInfo := fmt.Sprintf(\"%d bytes%s\", len(body), printableBody)\n\n\tif response.StatusCode != expectedStatusCode {\n\t\treturn extraInfo, fmt.Errorf(\"expected status code %d, got %d\", expectedStatusCode, response.StatusCode)\n\t}\n\n\treturn extraInfo, nil\n}\n\nfunc testDNSResolution(domain string) (string, error) {\n\tips, err := net.LookupIP(domain)\n\n\tvar ipStrings []string\n\tif err == nil {\n\t\tfor i := range ips {\n\t\t\tipStrings = append(ipStrings, ips[i].String())\n\t\t}\n\t}\n\n\treturn strings.Join(ipStrings, \", \"), err\n}\n","sourceCodeStart":174,"sourceCodeEnd":210,"githubUrl":"https://github.com/glanceapp/glance/blob/91324e8de762702e97b0ac5c8e36271d644d8642/internal/glance/diagnose.go#L174-L210","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Check the response body snippet in the error output to identify what actually answered","Verify the reverse proxy route and port forwarding map to the glance port","If auth is enabled, confirm the diagnostic request carries the required credentials/cookie or that the checked path is exempted","Ensure nothing else is bound to the configured port (`ss -ltnp | grep <port>`)"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"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.","preventionTips":["Health-check reverse proxy upstreams before glance diagnostics run","Keep the configured port exclusive to glance","When auth is on, ensure diagnostic paths/credentials are wired"],"tags":["http","network","diagnostics"],"backgroundTag":null,"analyzedSha":"91324e8de762702e97b0ac5c8e36271d644d8642","analyzedAt":"2026-08-15T14:12:54.279Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}