{"record":{"id":"d9acdb54e45f1ec1","repo":"GoogleCloudPlatform/microservices-demo","slug":"failed-to-unmarshal-body","errorCode":null,"errorMessage":"failed to unmarshal body","messagePattern":"failed to unmarshal body","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"src/frontend/handlers.go","lineNumber":489,"sourceCode":"\treq.Header.Set(\"Accept\", \"application/json\")\n\tres, err := http.DefaultClient.Do(req)\n\tif err != nil {\n\t\trenderHTTPError(log, r, w, errors.Wrap(err, \"failed to send request\"), http.StatusInternalServerError)\n\t\treturn\n\t}\n\n\tbody, err := io.ReadAll(res.Body)\n\tif err != nil {\n\t\trenderHTTPError(log, r, w, errors.Wrap(err, \"failed to read response\"), http.StatusInternalServerError)\n\t\treturn\n\t}\n\n\tfmt.Printf(\"%+v\\n\", body)\n\tfmt.Printf(\"%+v\\n\", res)\n\n\terr = json.Unmarshal(body, &response)\n\tif err != nil {\n\t\trenderHTTPError(log, r, w, errors.Wrap(err, \"failed to unmarshal body\"), http.StatusInternalServerError)\n\t\treturn\n\t}\n\n\t// respond with the same message\n\tjson.NewEncoder(w).Encode(Response{Message: response.Content})\n\n\tw.WriteHeader(http.StatusOK)\n}\n\nfunc (fe *frontendServer) setCurrencyHandler(w http.ResponseWriter, r *http.Request) {\n\tlog := r.Context().Value(ctxKeyLog{}).(logrus.FieldLogger)\n\tcur := r.FormValue(\"currency_code\")\n\tpayload := validator.SetCurrencyPayload{Currency: cur}\n\tif err := payload.Validate(); err != nil {\n\t\trenderHTTPError(log, r, w, validator.ValidationErrorResponse(err), http.StatusUnprocessableEntity)\n\t\treturn\n\t}\n\tlog.WithField(\"curr.new\", payload.Currency).WithField(\"curr.old\", currentCurrency(r)).","sourceCodeStart":471,"sourceCodeEnd":507,"githubUrl":"https://github.com/GoogleCloudPlatform/microservices-demo/blob/72ba613a05f7fcee51cf1d0badff401b6ae7074d/src/frontend/handlers.go#L471-L507","documentation":"json.Unmarshal failed to decode the assistant's response body into LLMResponse ({content, details}). The assistant replied, but the body is not valid JSON or does not match the expected schema (HTML error page, empty body, or version drift).","triggerScenarios":"Thrown at src/frontend/handlers.go:489 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check res.StatusCode before decoding; handle non-2xx responses (often non-JSON) separately.","Log the raw body to inspect the actual payload shape.","Align LLMResponse with the assistant's real schema or decode into a map first.","Ensure the assistant always returns application/json, even on internal errors."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"72ba613a05f7fcee51cf1d0badff401b6ae7074d","analyzedAt":"2026-09-02T01:15:09.673Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}