Skip to content

Commit 65b0cdc

Browse files
authored
Merge pull request #87 from the-commons-project/improvement-to-error-handling
Improvement to error handling
2 parents 3887419 + 86912da commit 65b0cdc

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/lib/SHX.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,12 @@ async function _verifySHX(shx, passcode) {
167167
for (const i in resolved.rawBundles) {
168168
addRawBundle(statusObj, resolved.rawBundles[i]);
169169
}
170-
170+
// Check if the 'section' field is missing or empty in each FHIR bundle
171+
statusObj.bundles.forEach(bundle => {
172+
if (!bundle.fhir || !bundle.fhir.entry || !bundle.fhir.entry.some(entry => entry.resource && entry.resource.section)) {
173+
throw new DataMissingError("The provided Smart Health Link does not contain any healthcare data.");
174+
}
175+
});
171176
// build up our organized resources
172177
const labelCounters = { };
173178
for (const i in statusObj.bundles) {
@@ -240,11 +245,6 @@ async function resolveSHX(shx, passcode) {
240245
// wasn't JSON, so assume it's an SHC... we'll error on verification if not
241246
resolved.verifiableCredentials.push(target);
242247
}
243-
// Throw DataMissingError if no data found
244-
if (resolved.verifiableCredentials.length === 0 && resolved.rawBundles.length === 0) {
245-
throw new DataMissingError("No data found in the SHL content.");
246-
}
247-
248248
return(resolved);
249249
}
250250

0 commit comments

Comments
 (0)