{"record":{"id":"53b0214a0baca7bf","repo":"apache/beam","slug":"error-listing-fhir-resources-from-s-s","errorCode":null,"errorMessage":"Error listing FHIR resources from %s: %s","messagePattern":"Error listing FHIR resources from (.+?): (.+?)","errorType":"exception","errorClass":"NoSuchElementException","httpStatus":null,"severity":"error","filePath":"sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/healthcare/HttpHealthcareApiClient.java","lineNumber":996,"sourceCode":"                \"Failed to list first page of FHIR resources from %s: %s\",\n                fhirStore, e.getMessage()));\n      }\n    }\n\n    @Override\n    public JsonArray next() throws NoSuchElementException {\n      try {\n        HttpBody response = executeFhirRequest();\n        this.isFirstRequest = false;\n        JsonObject jsonResponse =\n            JsonParser.parseString(mapper.writeValueAsString(response)).getAsJsonObject();\n        JsonArray links = jsonResponse.getAsJsonArray(\"link\");\n        this.pageToken = parsePageToken(links);\n        JsonArray resources = jsonResponse.getAsJsonArray(\"entry\");\n        return resources;\n      } catch (IOException e) {\n        this.pageToken = null;\n        throw new NoSuchElementException(\n            String.format(\"Error listing FHIR resources from %s: %s\", fhirStore, e.getMessage()));\n      }\n    }\n\n    private HttpBody executeFhirRequest() throws IOException {\n      switch (fhirMethod) {\n        case PATIENT_EVERYTHING:\n          return client.getPatientEverything(resourceName, parameters, pageToken);\n        case SEARCH:\n        default:\n          return client.searchFhirResource(fhirStore, resourceType, parameters, pageToken);\n      }\n    }\n\n    private static String parsePageToken(JsonArray links) throws MalformedURLException {\n      for (JsonElement e : links) {\n        JsonObject link = e.getAsJsonObject();\n        if (link.get(\"relation\").getAsString().equalsIgnoreCase(\"next\")) {","sourceCodeStart":978,"sourceCodeEnd":1014,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/healthcare/HttpHealthcareApiClient.java#L978-L1014","documentation":"The FHIR resource listing page iterator in HttpHealthcareApiClient throws NoSuchElementException when fetching a subsequent page of FHIR search results raises IOException; pageToken is reset to null so iteration ends. The underlying API/network error text is appended after the store name.","triggerScenarios":"Second and later calls to the FHIR resource page iterator's next()/fetch when the FHIR search REST request fails: transient network errors, expired OAuth token, rate limiting, or the fhirStore becoming unavailable mid-iteration.","commonSituations":"Long-running Beam FHIR pipelines that lose connectivity mid-read; quota/rate-limit 429 responses on large FHIR stores; token refresh failures; concurrent deletion of the store.","solutions":["Retry with backoff — transient network/5xx failures will abort iteration with this error","Re-check IAM (roles/healthcare.fhirStoreViewer) if the embedded cause is 403","Check the trailing %s for the concrete HTTP error (404 store deleted, 429 quota)","Resume iteration from the last successful pageToken if the pipeline supports checkpointing"],"exampleFix":"// before\nthrow new NoSuchElementException(String.format(\"Error listing FHIR resources from %s: %s\", fhirStore, e.getMessage()));\n// after\n// wrap iteration in retry\nFluentBackoff backoff = FluentBackoff.DEFAULT.withMaxRetries(3).withInitialBackoff(Duration.standardSeconds(1));\ntry {\n  return BackOffUtils.next(sleeper, backoff.backoff(), () -> fetchPage(fhirStore));\n} catch (IOException | InterruptedException e) {\n  throw new RuntimeException(\"FHIR listing failed for \" + fhirStore, e);\n}","handlingStrategy":"retry","validationCode":"java\nif (pageToken != null && pageToken.isEmpty()) {\n  throw new IllegalArgumentException(\"Empty pageToken for FHIR listing\");\n}","typeGuard":null,"tryCatchPattern":"java\ntry {\n  resources = fetchNextPage(fhirStore);\n} catch (NoSuchElementException e) {\n  // retry with exponential backoff; surface embedded cause after retries exhausted\n  throw new IOException(\"FHIR pagination failed: \" + e.getMessage(), e);\n}","preventionTips":["Wrap page fetches in retry with exponential backoff for 5xx/network blips","Monitor rate limits on large FHIR stores","Keep OAuth token refresh healthy in long-running pipelines","Persist the last good pageToken for resumable reads"],"tags":["java","google-cloud-healthcare","fhir","io-exception","pagination"],"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"}