{"record":{"id":"71017077f7e9a375","repo":"Netflix/chaosmonkey","slug":"unexpected-response-code-d-body-s","errorCode":null,"errorMessage":"unexpected response code: %d, body: %s","messagePattern":"unexpected response code: (.+?), body: (.+?)","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"spinnaker/terminator.go","lineNumber":99,"sourceCode":"\tpayload := killJSONPayload(ins, otherID, s.user)\n\tresp, err := s.client.Post(url, \"application/json\", bytes.NewReader(payload))\n\tif err != nil {\n\t\treturn errors.Wrap(err, fmt.Sprintf(\"POST to %s failed, (body '%s')\", url, string(payload)))\n\t}\n\n\tdefer func() {\n\t\tif cerr := resp.Body.Close(); cerr != nil && err == nil {\n\t\t\terr = errors.Wrap(cerr, fmt.Sprintf(\"failed to close response body of %s\", url))\n\t\t}\n\t}()\n\n\tif resp.StatusCode != http.StatusOK {\n\t\tlog.Printf(\"Unexpected response: %d\", resp.StatusCode)\n\t\tcontents, err := ioutil.ReadAll(resp.Body)\n\t\tif err != nil {\n\t\t\treturn errors.Wrap(err, \"failed to read response body\")\n\t\t}\n\t\treturn fmt.Errorf(\"unexpected response code: %d, body: %s\", resp.StatusCode, string(contents))\n\t}\n\n\treturn nil\n}\n\n// killJsonPayload generates the JSON request body for terminating an instance\n// otherID is an optional second instance ID, as some backends may have a second\n// identifer.\nfunc killJSONPayload(ins chaosmonkey.Instance, otherID string, spinnakerUser string) []byte {\n\tvar desc string\n\tif otherID != \"\" {\n\t\tdesc = fmt.Sprintf(\"Chaos Monkey terminate instance: %s %s (%s, %s, %s)\", ins.ID(), otherID, ins.AccountName(), ins.RegionName(), ins.ASGName())\n\t} else {\n\t\tdesc = fmt.Sprintf(\"Chaos Monkey terminate instance: %s (%s, %s, %s)\", ins.ID(), ins.AccountName(), ins.RegionName(), ins.ASGName())\n\t}\n\n\tp := killPayload{\n\t\tApplication: ins.AppName(),","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/Netflix/chaosmonkey/blob/eaa28fb761c0ebe8644d1333e5d164e9cc3071e9/spinnaker/terminator.go#L81-L117","documentation":"Returned by Terminator.Execute when Spinnaker responds to the termination POST with a status other than 200; the body of the non-OK response is read and included to show why Spinnaker rejected the terminate request.","triggerScenarios":"Calling spinnaker.Terminator.Execute (kill) when the Spinnaker API returns 4xx (bad auth, bad payload) or 5xx (server error).","commonSituations":"Expired Spinnaker auth token, malformed instance ID, Spinnaker/Gate down or overloaded, wrong endpoint URL.","solutions":["Log/inspect the returned body to see Spinnaker's error detail","Verify Spinnaker API URL and authentication credentials","Check that the instance ID/account/region in the kill payload is valid","Check Spinnaker server health if 5xx persists"],"exampleFix":"// before\nreturn fmt.Errorf(\"unexpected response code: %d, body: %s\", resp.StatusCode, string(contents))\n// after\nif resp.StatusCode == http.StatusUnauthorized {\n    return fmt.Errorf(\"spinnaker auth failed (401), refresh credentials\")\n}\nreturn fmt.Errorf(\"unexpected response code: %d, body: %s\", resp.StatusCode, string(contents))","handlingStrategy":"try-catch","validationCode":"// preflight: check Spinnaker reachability and auth\nresp, err := http.Get(spinURL + \"/health\")\nif err != nil || resp.StatusCode != http.StatusOK {\n    return fmt.Errorf(\"spinnaker unreachable or unhealthy\")\n}","typeGuard":null,"tryCatchPattern":"err := terminator.Execute(instance)\nif err != nil {\n    if strings.Contains(err.Error(), \"401\") || strings.Contains(err.Error(), \"403\") {\n        // refresh credentials and retry once\n    } else if strings.Contains(err.Error(), \"unexpected response code: 5\") {\n        // retry with backoff\n    }\n}","preventionTips":["Keep Spinnaker auth tokens fresh","Validate instance IDs before killing","Add retries for 5xx only","Log the response body for diagnosis"],"tags":["http","spinnaker","api"],"backgroundTag":"unexpected-http-status","analyzedSha":"eaa28fb761c0ebe8644d1333e5d164e9cc3071e9","analyzedAt":"2026-09-03T17:04:39.020Z","contentChangedAt":"2026-09-03T17:04:39.020Z","schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}