{"record":{"id":"e2e8c079531366a8","repo":"plandex-ai/plandex","slug":"error-decoding-request-body-e2e8c0","errorCode":null,"errorMessage":"Error decoding request body","messagePattern":"Error decoding request body","errorType":"http","errorClass":"http","httpStatus":500,"severity":"error","filePath":"app/server/handlers/settings.go","lineNumber":105,"sourceCode":"\n\tvars := mux.Vars(r)\n\tplanId := vars[\"planId\"]\n\tbranch := vars[\"branch\"]\n\n\tlog.Println(\"planId: \", planId, \"branch: \", branch)\n\n\tplan := authorizePlan(w, planId, auth)\n\n\tif plan == nil {\n\t\treturn\n\t}\n\n\tvar req shared.UpdateSettingsRequest\n\terr := json.NewDecoder(r.Body).Decode(&req)\n\n\tif err != nil {\n\t\tlog.Println(\"Error decoding request body: \", err)\n\t\thttp.Error(w, \"Error decoding request body\", http.StatusInternalServerError)\n\t\treturn\n\t}\n\n\tif req.ModelPackName == \"\" && req.ModelPack == nil {\n\t\tlog.Println(\"No model pack name or model pack provided\")\n\t\thttp.Error(w, \"No model pack name or model pack provided\", http.StatusBadRequest)\n\t\treturn\n\t}\n\n\tif req.ModelPackName != \"\" {\n\t\tif mp, builtIn := shared.BuiltInModelPacksByName[req.ModelPackName]; builtIn {\n\t\t\tif os.Getenv(\"IS_CLOUD\") != \"\" && mp.LocalProvider != \"\" {\n\t\t\t\tmsg := fmt.Sprintf(\"Built-in local model pack %s can't be used on Plandex Cloud\", req.ModelPackName)\n\t\t\t\tlog.Println(msg)\n\t\t\t\thttp.Error(w, msg, http.StatusUnprocessableEntity)\n\t\t\t\treturn\n\t\t\t}\n\t\t}","sourceCodeStart":87,"sourceCodeEnd":123,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/server/handlers/settings.go#L87-L123","documentation":"UpdateSettingsHandler decodes the request body into shared.UpdateSettingsRequest using json.NewDecoder(r.Body).Decode. A decode failure (malformed JSON, wrong types, empty body) triggers a logged message and an HTTP 500 response. Note the semantics: this is really a client-side bad request even though the server replies 500.","triggerScenarios":"Request body is not valid JSON; body is empty; a field has the wrong type (e.g. modelPack as a string instead of object); body already consumed by a prior read; charset/encoding issues in Content-Type.","commonSituations":"CLI or API client sending truncated or hand-built JSON; missing Content-Type causing client to send form data; proxy/gateway mangling the body; sending JSON with incorrect nesting for UpdateSettingsRequest.","solutions":["Send a valid JSON body matching shared.UpdateSettingsRequest (check modelPackName is a string or modelPack an object)","Set Content-Type: application/json on the request","Validate the payload with a JSON linter before sending","If you control the server, return 400 instead of 500 and use http.MaxBytesReader for oversized bodies"],"exampleFix":"// before\nerr := json.NewDecoder(r.Body).Decode(&req)\nif err != nil {\n    http.Error(w, \"Error decoding request body\", http.StatusInternalServerError)\n// after\nerr := json.NewDecoder(r.Body).Decode(&req)\nif err != nil {\n    http.Error(w, \"Invalid JSON body: \"+err.Error(), http.StatusBadRequest)","handlingStrategy":"validation","validationCode":"body, err := json.Marshal(shared.UpdateSettingsRequest{ModelPackName: \"default\"})\nif err != nil {\n    return err\n}\nreq, _ := http.NewRequest(\"POST\", url, bytes.NewReader(body))\nreq.Header.Set(\"Content-Type\", \"application/json\")","typeGuard":null,"tryCatchPattern":"resp, err := client.UpdateSettings(ctx, req)\nif err != nil {\n    var apiErr *APIError\n    if errors.As(err, &apiErr) && apiErr.StatusCode == 500 && strings.Contains(apiErr.Message, \"Error decoding request body\") {\n        // fix payload JSON and resend\n    }\n    return err\n}","preventionTips":["Always send Content-Type: application/json","Validate the payload against shared.UpdateSettingsRequest field types","Lint/generate the JSON with a typed struct instead of string concatenation","Don't reuse or re-read a request body that was already consumed"],"tags":["json","http","request-body"],"backgroundTag":"invalid-json-body","analyzedSha":"e2d772072efadbe41d2946d97d79be55532dbab5","analyzedAt":"2026-09-05T20:56:53.631Z","contentChangedAt":"2026-09-05T20:56:53.631Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}