Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions healthcare/fhir/deleteFhirStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const main = (
auth: new google.auth.GoogleAuth({
scopes: ['https://www.googleapis.com/auth/cloud-platform'],
}),
responseType: 'json',
});

const deleteFhirStore = async () => {
Expand All @@ -38,8 +39,12 @@ const main = (
const name = `projects/${projectId}/locations/${cloudRegion}/datasets/${datasetId}/fhirStores/${fhirStoreId}`;
const request = {name};

await healthcare.projects.locations.datasets.fhirStores.delete(request);
console.log(`Deleted FHIR store: ${fhirStoreId}`);
try {
await healthcare.projects.locations.datasets.fhirStores.delete(request);
console.log(`Deleted FHIR store: ${fhirStoreId}`);
} catch (error) {
console.error('Error deleting FHIR store:', error.message || error);
}
Comment on lines +45 to +47
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

While adding try...catch is good for error handling, swallowing the error causes the script to exit with a success code (0) even when the deletion fails. This can be misleading for users or automated scripts. To correctly signal failure, you should set process.exitCode = 1 in the catch block. This signals an error without abruptly terminating the process, which is a better practice for command-line scripts.

    } catch (error) {
      console.error('Error deleting FHIR store:', error.message || error);
      process.exitCode = 1;
    }
References
  1. The code logs the error as suggested by the rule, but it allows the script to terminate with a success status. This can be misleading. The suggestion to use process.exitCode allows signaling failure without abruptly terminating the process with process.exit().

};

deleteFhirStore();
Expand Down
Loading