{"record":{"id":"2986df57717fa263","repo":"apache/beam","slug":"could-not-parse-body-from-execute-bundle-response","errorCode":null,"errorMessage":"could not parse body from execute bundle response","messagePattern":"could not parse body from execute bundle response","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/io/fhirio/execute_bundles.go","lineNumber":88,"sourceCode":"\tif err != nil {\n\t\tfn.resourcesErrorCount.Inc(ctx, 1)\n\t\temitFailure(errors.Wrap(err, \"could not extract body from execute bundles response\").Error())\n\t\treturn\n\t}\n\n\tfn.processResponseBody(ctx, body, emitSuccess, emitFailure)\n}\n\nfunc (fn *executeBundleFn) processResponseBody(ctx context.Context, body string, emitSuccess, emitFailure func(string)) {\n\tvar bodyFields struct {\n\t\tType    string `json:\"type\"`\n\t\tEntries []any  `json:\"entry\"`\n\t}\n\n\terr := json.NewDecoder(strings.NewReader(body)).Decode(&bodyFields)\n\tif err != nil {\n\t\tfn.resourcesErrorCount.Inc(ctx, 1)\n\t\temitFailure(errors.Wrap(err, \"could not parse body from execute bundle response\").Error())\n\t\treturn\n\t}\n\n\tif bodyFields.Entries == nil {\n\t\treturn\n\t}\n\n\t// A BATCH bundle returns a success response even if entries have failures, as\n\t// entries are executed separately. However, TRANSACTION bundles should return\n\t// error response (in client.executeBundle call) if any entry fails. Therefore,\n\t// for BATCH bundles we need to parse the error and success counters.\n\tswitch bodyFields.Type {\n\tcase bundleResponseTypeTransaction:\n\t\tfn.resourcesSuccessCount.Inc(ctx, int64(len(bodyFields.Entries)))\n\t\temitSuccess(body)\n\tcase bundleResponseTypeBatch:\n\t\tfor _, entry := range bodyFields.Entries {\n\t\t\tvar entryFields struct {","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/io/fhirio/execute_bundles.go#L70-L106","documentation":"processResponseBody decodes the executeBundle response body as JSON into a struct with an 'entry' array. If the body is not valid JSON or has an incompatible shape, json.Decode fails and the error is wrapped with this message, the error counter is incremented, and the failure is emitted. This indicates the FHIR server returned something other than a well-formed Bundle response.","triggerScenarios":"json.NewDecoder(strings.NewReader(body)).Decode(&bodyFields) errors: the response body is empty, HTML (e.g. a proxy error page), truncated JSON, or otherwise not a FHIR Bundle object.","commonSituations":"A load balancer or auth proxy returning an HTML 502 page; sending requests to a non-FHIR endpoint; FHIR store returning an OperationOutcome with unexpected content-type that was not rejected earlier; body truncated by an interrupted connection.","solutions":["Log the raw response body on failure to see what was actually returned","Verify the endpoint URL is a real FHIR store executeBundle endpoint","Check for proxies/gateways injecting HTML error pages and bypass them","Upgrade the Beam SDK — later fhirio versions harden body extraction and status checks","Validate bundle size/timeouts so responses are not truncated mid-stream"],"exampleFix":"// before\nerr := json.NewDecoder(strings.NewReader(body)).Decode(&bodyFields)\nif err != nil { emitFailure(errors.Wrap(err, \"could not parse body...\")) }\n// after\nif ct := response.Header.Get(\"Content-Type\"); !strings.Contains(ct, \"application/json\") {\n    emitFailure(fmt.Sprintf(\"unexpected content-type %q; body: %.200s\", ct, body))\n    return\n}\nerr := json.NewDecoder(strings.NewReader(body)).Decode(&bodyFields)","handlingStrategy":"try-catch","validationCode":"// pre-validate the endpoint returns JSON before batch runs\nresp, _ := http.Get(fhirStoreURL + \"/metadata\")\nct := resp.Header.Get(\"Content-Type\")\nif !strings.Contains(ct, \"application/json\") { return fmt.Errorf(\"endpoint not JSON: %s\", ct) }","typeGuard":null,"tryCatchPattern":"// decode defensively before handing to fhirio\nvar probe map[string]any\nif err := json.Unmarshal([]byte(body), &probe); err != nil {\n    return fmt.Errorf(\"non-JSON body from FHIR store: %w\", err)\n}","preventionTips":["Ensure no proxy/auth gateway injects HTML error pages","Point at the correct healthcare.googleapis.com executeBundle endpoint","Check Content-Type on responses before parsing","Pin a recent Beam SDK version for hardened response handling"],"tags":["go","fhirio","json","response-parsing"],"backgroundTag":"json-decode-failed","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}