{"record":{"id":"fda3ada697913341","repo":"apache/beam","slug":"response-contains-bad-status-v","errorCode":null,"errorMessage":"response contains bad status: [%v]","messagePattern":"response contains bad status: \\[(.+?)\\]","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/io/fhirio/common.go","lineNumber":59,"sourceCode":"\toperationErrorCounterName   = baseMetricPrefix + \"operation_error_count\"\n\toperationSuccessCounterName = baseMetricPrefix + \"operation_success_count\"\n\tsuccessCounterName          = baseMetricPrefix + \"resource_success_count\"\n\tpageTokenParameterKey       = \"_page_token\"\n)\n\nvar backoffDuration = [...]time.Duration{time.Second, 5 * time.Second, 10 * time.Second, 15 * time.Second}\n\nfunc executeAndRecordLatency[T any](ctx context.Context, latencyMs *beam.Distribution, executionSupplier func() (T, error)) (T, error) {\n\ttimeBeforeReadRequest := time.Now()\n\tresult, err := executionSupplier()\n\tlatencyMs.Update(ctx, time.Since(timeBeforeReadRequest).Milliseconds())\n\treturn result, err\n}\n\nfunc extractBodyFrom(response *http.Response) (string, error) {\n\terr := googleapi.CheckResponse(response)\n\tif err != nil {\n\t\treturn \"\", errors.Wrapf(err, \"response contains bad status: [%v]\", response.Status)\n\t}\n\n\tbodyBytes, err := io.ReadAll(response.Body)\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\n\treturn string(bodyBytes), nil\n}\n\ntype operationCounters struct {\n\tsuccessCount, errorCount beam.Counter\n}\n\nfunc (c *operationCounters) setup(namespace string) {\n\tc.successCount = beam.NewCounter(namespace, operationSuccessCounterName)\n\tc.errorCount = beam.NewCounter(namespace, operationErrorCounterName)\n}","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/io/fhirio/common.go#L41-L77","documentation":"fhirio's extractBodyFrom validates the HTTP response from the FHIR store API with googleapi.CheckResponse before reading the body. When the response carries a non-2xx status (auth failure, not found, malformed request, server error), CheckResponse returns an error and this error wraps it together with the response's status line, so the caller sees both the HTTP status and the underlying API error details.","triggerScenarios":"Any fhirio transformation (search, read, executeBundle, searchResourcesPaginated) hitting a FHIR store that returns an HTTP error status: invalid FHIR store path, insufficient IAM permissions, bad query parameters (e.g. invalid search filter), quota exceeded, or transient 5xx from the service.","commonSituations":"Misconfigured FHIR store URL or dataset/location path; missing roles/healthcare.fhirStore* IAM bindings on the pipeline's service account; expired or missing OAuth credentials; a search query with unsupported or misspelled FHIR search parameters yielding 400; transient 500/503 during high load.","solutions":["Check the wrapped googleapi error's code and body for the server-side detail (401/403 → fix credentials/IAM; 404 → fix store path; 400 → fix query)","Verify the pipeline's service account has the required healthcare.fhirStore permissions (viewer/searcher roles)","Validate the FHIR store resource path and search parameters against the API docs before retrying","Wrap the call in retry with backoff for transient 5xx statuses"],"exampleFix":"// before\nresp, err := client.Search(ctx, store, \"Patient\", badParams) // 400\n// after\nparams := url.Values{}\nparams.Set(\"family\", \"Smith\") // valid FHIR search parameter\nresp, err := client.Search(ctx, validStorePath, \"Patient\", params)\nif err != nil {\n    var gerr *googleapi.Error\n    if errors.As(err, &gerr) { log.Printf(\"status %d: %s\", gerr.Code, gerr.Body) }\n}","handlingStrategy":"try-catch","validationCode":"func validateFHIRStorePath(storePath string) error {\n    re := regexp.MustCompile(`^projects/[^/]+/locations/[^/]+/datasets/[^/]+/fhirStores/[^/]+$`)\n    if !re.MatchString(storePath) {\n        return fmt.Errorf(\"invalid FHIR store path: %s\", storePath)\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"result, err := fhirio.Search(s, store, \"Patient\").Get(...)\nif err != nil {\n    var gerr *googleapi.Error\n    if errors.As(err, &gerr) {\n        switch gerr.Code {\n        case 401, 403:\n            log.Printf(\"auth/IAM issue: %v\", gerr)\n        case 404:\n            log.Printf(\"store not found: %v\", gerr)\n        case 400:\n            log.Printf(\"bad query: %v\", gerr)\n        default:\n            // transient 5xx: retry with backoff\n        }\n    }\n}","preventionTips":["Grant the pipeline service account the correct healthcare.fhirStore roles","Validate the FHIR store resource path before deploying","Test search parameters against the FHIR API before running the pipeline","Implement retry-with-backoff for transient 5xx responses"],"tags":["http","fhir","gcp","api-error"],"backgroundTag":"http-error-response","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"}