{"record":{"id":"3b4684a8c9b09a56","repo":"thanos-io/thanos","slug":"got-non-200-response-code-v-response-v","errorCode":null,"errorMessage":"got non-200 response code: %v, response: %v","messagePattern":"got non-200 response code: (.+?), response: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/promclient/promclient.go","lineNumber":329,"sourceCode":"\tif err != nil {\n\t\treturn Flags{}, errors.New(\"failed to read body\")\n\t}\n\n\tswitch resp.StatusCode {\n\tcase 404:\n\t\treturn Flags{}, ErrFlagEndpointNotFound\n\tcase 200:\n\t\tvar d struct {\n\t\t\tData Flags `json:\"data\"`\n\t\t}\n\n\t\tif err := json.Unmarshal(b, &d); err != nil {\n\t\t\treturn Flags{}, errors.Wrapf(err, \"unmarshal response: %v\", string(b))\n\t\t}\n\n\t\treturn d.Data, nil\n\tdefault:\n\t\treturn Flags{}, errors.Errorf(\"got non-200 response code: %v, response: %v\", resp.StatusCode, string(b))\n\t}\n\n}\n\n// Snapshot will request Prometheus to perform snapshot in directory returned by this function.\n// Returned directory is relative to Prometheus data-dir.\n// NOTE: `--web.enable-admin-api` flag has to be set on Prometheus.\n// Added to Prometheus from v2.1.\n// TODO(bwplotka): Add metrics.\nfunc (c *Client) Snapshot(ctx context.Context, base *url.URL, skipHead bool) (string, error) {\n\tu := *base\n\tu.Path = path.Join(u.Path, \"/api/v1/admin/tsdb/snapshot\")\n\n\treq, err := http.NewRequest(\n\t\thttp.MethodPost,\n\t\tu.String(),\n\t\tstrings.NewReader(url.Values{\"skip_head\": []string{strconv.FormatBool(skipHead)}}.Encode()),\n\t)","sourceCodeStart":311,"sourceCodeEnd":347,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/promclient/promclient.go#L311-L347","documentation":"Client.ConfiguredFlags treats any HTTP status other than 200 as an error and returns the status code plus the raw response body. The library cannot interpret flags from an error response, so it surfaces both to help diagnose the server-side cause.","triggerScenarios":"Prometheus (or an intermediary) answered /api/v1/status/flags with 4xx/5xx: wrong endpoint path, auth required (401/403), service down (502/503), or method not allowed.","commonSituations":"Misconfigured --prometheus.url pointing to the UI root instead of the API base; reverse proxy requiring authentication; Prometheus restarted or temporarily unavailable; hitting a Thanos Query endpoint that lacks the flags status API.","solutions":["Read the status code and body in the error message to identify the server-side cause","Fix the base URL so that <base>/api/v1/status/flags resolves correctly","Check for required auth (401/403) and add credentials or allowlist the client","Verify the Prometheus instance is up and healthy via /-/healthy"],"exampleFix":"// before\nu, _ := url.Parse(\"http://prometheus:9090/prometheus\") // wrong path prefix\n// after\nu, _ := url.Parse(\"http://prometheus:9090\") // library appends /api/v1/status/flags","handlingStrategy":"try-catch","validationCode":"resp, err := http.Get(baseURL + \"/api/v1/status/flags\")\nif err != nil { return err }\nif resp.StatusCode != 200 { return fmt.Errorf(\"status flags endpoint returned %d\", resp.StatusCode) }","typeGuard":"func isNon200(err error) bool {\n    return err != nil && strings.Contains(err.Error(), \"non-200 response code\")\n}","tryCatchPattern":"flags, err := client.ConfiguredFlags(ctx)\nif err != nil {\n    if isNon200(err) { /* check upstream health/auth from code+body in msg */ }\n    return err\n}","preventionTips":["Health-check /-/healthy before calling status APIs","Ensure auth is configured when proxies gate endpoints","Use the correct base URL so /api/v1 paths resolve"],"tags":["http","prometheus","status-code"],"backgroundTag":"http-non-200-response","analyzedSha":"35b8b991177def87ed52dcf10f9b6d87f07282c8","analyzedAt":"2026-09-07T01:49:59.689Z","contentChangedAt":"2026-09-07T01:49:59.689Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}