{"record":{"id":"517a987765b5c112","repo":"VictoriaMetrics/VictoriaMetrics","slug":"unexpected-status-code-returned-from-q-d-expec-517a98","errorCode":null,"errorMessage":"unexpected status code returned from %q: %d; expecting %d; response body: %q","messagePattern":"unexpected status code returned from %q: (.+?); expecting (.+?); response body: %q","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/snapshot/snapshot.go","lineNumber":60,"sourceCode":"\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"cannot create http client for -snapshot.createURL=%q: %w\", createSnapshotURL, err)\n\t}\n\treq, err := http.NewRequestWithContext(ctx, http.MethodPost, createSnapshotURL, nil)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"cannot create request for -snapshot.createURL=%q: %w\", createSnapshotURL, err)\n\t}\n\tresp, err := hc.Do(req)\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\tdefer resp.Body.Close()\n\n\tbody, err := io.ReadAll(resp.Body)\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\tif resp.StatusCode != http.StatusOK {\n\t\treturn \"\", fmt.Errorf(\"unexpected status code returned from %q: %d; expecting %d; response body: %q\", u.Redacted(), resp.StatusCode, http.StatusOK, body)\n\t}\n\n\tsnap := snapshot{}\n\terr = json.Unmarshal(body, &snap)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"cannot parse JSON response from %q: %w; response body: %q\", u.Redacted(), err, body)\n\t}\n\n\tif snap.Status == \"ok\" {\n\t\tlogger.Infof(\"Snapshot %s created\", snap.Snapshot)\n\t\treturn snap.Snapshot, nil\n\t}\n\tif snap.Status == \"error\" {\n\t\treturn \"\", fmt.Errorf(\"snapshot status: %q; msg: %q\", snap.Status, snap.Msg)\n\t}\n\treturn \"\", fmt.Errorf(\"snapshot status unknown: %q\", snap.Status)\n}\n","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/VictoriaMetrics/VictoriaMetrics/blob/5079fb58f1e8e62113f90c945ad71586c797d770/lib/snapshot/snapshot.go#L42-L78","documentation":"snapshot.Create expects the snapshot API to answer HTTP 200 with a JSON snapshot descriptor. Any other status code produces this error containing the redacted URL, the actual status, the expected 200, and the response body — which typically holds VictoriaMetrics' own error explanation. The URL is Redacted() so credentials are not leaked.","triggerScenarios":"The POST to -snapshot.createURL returns a non-200 status: 404 (wrong path or non-VictoriaMetrics server), 403 (auth required), 400, or 5xx from the storage node.","commonSituations":"Pointing -snapshot.createURL at the wrong service/port, missing -httpAuth.* credentials when the server has auth enabled, or a reverse proxy returning 403/502, or snapshot creation failing server-side due to storage issues.","solutions":["Read the response body in the error — VictoriaMetrics returns a descriptive message for the failure.","Verify the URL path is /snapshot/create on the correct VictoriaMetrics (or vmselect) port.","Add authentication flags/credentials if the server returns 401/403.","Check VictoriaMetrics server logs at the same timestamp for the underlying storage/snapshot error.","Confirm no reverse proxy/ingress intercepts the request (look for 403/404/502 from the proxy instead of VM)."],"exampleFix":"// before\n-snapshot.createURL=http://vm:8428/snapshots/create   // 404\n// after\n-snapshot.createURL=http://vm:8428/snapshot/create    // correct API path","handlingStrategy":"try-catch","validationCode":"// pre-check endpoint reachability\nresp, err := http.Get(baseURL + \"/health\")\nif err != nil || resp.StatusCode != 200 {\n\tlog.Fatalf(\"endpoint not healthy\")\n}","typeGuard":null,"tryCatchPattern":"name, err := snapshot.Create(ctx, createURL)\nif err != nil && strings.Contains(err.Error(), \"unexpected status code\") {\n\t// parse body from error message / check server logs, then correct auth or path\n\tlog.Fatalf(\"snapshot API rejected request: %v\", err)\n}","preventionTips":["Use the exact API path /snapshot/create on the correct VM port","Configure auth flags when the server has authentication enabled","Check VictoriaMetrics server logs when a non-200 is returned"],"tags":["snapshot","http","status-code","network","api"],"backgroundTag":"unexpected-http-status","analyzedSha":"5079fb58f1e8e62113f90c945ad71586c797d770","analyzedAt":"2026-09-03T18:10:26.153Z","contentChangedAt":"2026-09-03T18:10:26.153Z","schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}