{"record":{"id":"fc71855fdcaedddf","repo":"hasura/graphql-engine","slug":"request-failed-url-s-status-code-v-status-s","errorCode":null,"errorMessage":"request failed: url: %s status code: %v status: %s \n%s","messagePattern":"request failed: url: (.+?) status code: (.+?) status: (.+?) \n(.+?)","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/util/server.go","lineNumber":144,"sourceCode":"\treq, err := http.NewRequest(http.MethodGet, versionEndpoint, nil)\n\tif err != nil {\n\t\treturn errors.E(\n\t\t\top,\n\t\t\tfmt.Errorf(\"failed to create GET request to %s: %w\", versionEndpoint, err),\n\t\t)\n\t}\n\n\tvar responseBs bytes.Buffer\n\n\tresp, err := httpClient.Do(context.Background(), req, &responseBs)\n\tif err != nil {\n\t\treturn errors.E(op, fmt.Errorf(\"making http request failed: %w\", err))\n\t}\n\n\tif resp.StatusCode != http.StatusOK {\n\t\treturn errors.E(\n\t\t\top,\n\t\t\tfmt.Errorf(\n\t\t\t\t\"request failed: url: %s status code: %v status: %s \\n%s\",\n\t\t\t\tversionEndpoint,\n\t\t\t\tresp.StatusCode,\n\t\t\t\tresp.Status,\n\t\t\t\tresponseBs.String(),\n\t\t\t),\n\t\t)\n\t}\n\n\treturn nil\n}\n","sourceCodeStart":126,"sourceCodeEnd":156,"githubUrl":"https://github.com/hasura/graphql-engine/blob/724551b9ae87845594ef0408cff0e50eb6c90dc5/cli/util/server.go#L126-L156","documentation":"GetServerStatus received an HTTP response whose status code is not 200 from the version endpoint (cli/util/server.go:144). The message includes the URL, status code, status text, and the response body, so the body usually reveals the server-side reason (error page, JSON error, auth challenge).","triggerScenarios":"Calling GetServerStatus when the endpoint returns 401/403 (auth required or bad token), 404 (wrong path or server version without the endpoint), 500 (server-side crash), or 502/503 (proxy/gateway in front of an unhealthy server).","commonSituations":"API token expired or missing so a gateway returns 401/403; reverse proxy (nginx/ingress) returning 502 because the backend is down; hitting an old server version that lacks /version; typo'd base path producing 404.","solutions":["Read the response body in the error message — it typically names the exact server-side cause.","Map the status: 401/403 -> fix/refresh credentials; 404 -> correct the base URL/path or upgrade the server; 5xx -> check server logs.","If behind a proxy, verify the upstream is healthy (the 502/503 is from the proxy, not the app).","Confirm the server version is new enough to expose the version endpoint."],"exampleFix":"// before\nst, err := util.GetServerStatus(u)\nif err != nil { return err }\n\n// after\nst, err := util.GetServerStatus(u)\nif err != nil {\n    if strings.Contains(err.Error(), \"status code: 401\") {\n        return fmt.Errorf(\"credentials rejected — run 'cli login': %w\", err)\n    }\n    return err\n}","handlingStrategy":"try-catch","validationCode":"// pre-flight with plain http to surface status early\nresp, err := http.Get(ep) //nolint\nif err == nil {\n    defer resp.Body.Close()\n    if resp.StatusCode != http.StatusOK {\n        return fmt.Errorf(\"endpoint unhealthy (HTTP %d) — check server/auth before continuing\", resp.StatusCode)\n    }\n}","typeGuard":null,"tryCatchPattern":"_, err := util.GetServerStatus(u)\nif err != nil && strings.Contains(err.Error(), \"status code:\") {\n    sc := extractStatusCode(err)\n    switch {\n    case sc == 401 || sc == 403:\n        return fmt.Errorf(\"auth failed — refresh credentials: %w\", err)\n    case sc == 404:\n        return fmt.Errorf(\"endpoint not found — check base URL/server version: %w\", err)\n    case sc >= 500:\n        return fmt.Errorf(\"server error — check server logs: %w\", err)\n    }\n}","preventionTips":["Parse the status code and body from the message to route to the right fix.","Keep credentials fresh and validate them at startup.","Verify the server version exposes the endpoint you're calling.","Monitor 5xx rates behind proxies to distinguish backend vs proxy failures."],"tags":["go","http","status-code","api-errors","auth"],"backgroundTag":"http-non-200-response","analyzedSha":"724551b9ae87845594ef0408cff0e50eb6c90dc5","analyzedAt":"2026-08-28T07:32:55.105Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}