Skip to content

Commit

Permalink
Reject error and status codes that indicate errors in browser environ…
Browse files Browse the repository at this point in the history
…ments
  • Loading branch information
jafeltra committed Dec 31, 2024
1 parent f64fc81 commit 2617104
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/registry/FHIRRegistryClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,17 @@ export class FHIRRegistryClient implements RegistryClient {

// Right now, this approach is needed for browser environments
if (this.isBrowserEnvironment) {
return new Promise(resolve => {
return new Promise((resolve, reject) => {
https
.get(url, res => {
resolve(res);
if (res.statusCode < 400) {
resolve(res);
} else {
reject(`Failed to download ${name}#${version} from ${url}`);
}
})
.on('error', e => {
console.log(e);
throw new Error(`Failed to download ${name}#${version} from ${url}`);
.on('error', () => {
reject(`Failed to download ${name}#${version} from ${url}`);
});
});
}
Expand Down

0 comments on commit 2617104

Please sign in to comment.