Skip to content

Commit 461fe6e

Browse files
committed
Add error handling for resource upload errors
1 parent d75f0d5 commit 461fe6e

File tree

3 files changed

+26
-10
lines changed

3 files changed

+26
-10
lines changed

src/lib/AddFile.svelte

+6-2
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@
8787
patientName = patient.name[0]?.given[0];
8888
}
8989
if (patientName) {
90-
console.log("Patient name: " + patientName);
9190
label = (patientName !== undefined ? patientName.charAt(0).toUpperCase() + patientName.slice(1).toLowerCase() + "'s" : "My")+ " Summary Link " + new Date().toISOString().slice(0, 10);
9291
}
9392
}
@@ -301,6 +300,10 @@
301300
status = newStatus;
302301
}
303302
303+
function showError(message: string) {
304+
fetchError = message;
305+
}
306+
304307
function confirmContent() {
305308
submitting = true;
306309
}
@@ -354,10 +357,11 @@
354357
<ResourceSelector
355358
bind:newResources={resourcesToReview}
356359
bind:patient={patient}
357-
bind:submitSelections={submitting}
360+
bind:submitting={submitting}
358361
bind:injectedResources={resourcesToInject}
359362
on:ips-retrieved={ async ({ detail }) => { uploadRetrievedIPS(detail) } }
360363
on:status-update={ ({ detail }) => { updateStatus(detail) } }
364+
on:error={ ({ detail }) => { showError(detail) } }
361365
/>
362366
{/if}
363367
</Accordion>

src/lib/ResourceSelector.svelte

+15-6
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,13 @@
3232
import OccupationalDataForHealth from './resource-templates/OccupationalDataForHealth.svelte';
3333
3434
export let newResources: Array<any> | undefined;
35-
export let submitSelections: boolean;
35+
export let submitting: boolean;
3636
export let patient: any | undefined;
3737
export let injectedResources: Record<string, {section: any|undefined; resources: { [key: string]: ResourceHelper }}>;
3838
3939
const components: Record<string, any> = {
4040
"DocumentReference": AdvanceDirective,
41+
"Consent": AdvanceDirective,
4142
"AllergyIntolerance": AllergyIntolerance,
4243
"Condition": Condition,
4344
"DiagnosticReport": DiagnosticReport,
@@ -57,9 +58,9 @@
5758
5859
const ipsDispatch = createEventDispatcher<{ 'ips-retrieved': IPSRetrieveEvent }>();
5960
const statusDispatch = createEventDispatcher<{ 'status-update': string }>();
61+
const errorDispatch = createEventDispatcher<{ 'error': string }>();
6062
let resources:{ [key: string]: ResourceHelper } = {};
6163
let resourcesByType:{ [key: string]: { [key: string]: ResourceHelper} } = {};
62-
let submitting = false;
6364
let reference: string;
6465
let patientReference: string;
6566
let patients: {[key: string]: ResourceHelper} = {};
@@ -78,8 +79,12 @@
7879
}
7980
}
8081
$: {
81-
if (submitSelections) {
82-
confirm();
82+
if (submitting) {
83+
confirm().catch(error => {
84+
submitting = false;
85+
console.error(error);
86+
errorDispatch("error", error.message);
87+
});
8388
}
8489
}
8590
@@ -224,15 +229,19 @@
224229
statusDispatch("status-update", "Preparing");
225230
let preparedResources = prepareResources(getSelectedResources());
226231
statusDispatch("status-update", "Adding data");
227-
reference = await uploadResources(preparedResources);
232+
try {
233+
reference = await uploadResources(preparedResources);
234+
} catch (e:any) {
235+
throw new Error("Unable to upload resources", {cause: e});
236+
}
228237
229238
let content:any;
230239
statusDispatch("status-update", "Building IPS");
231240
const contentResponse = await fetch(reference!, {
232241
headers: { accept: 'application/fhir+json' }
233242
}).then(function(response) {
234243
if (!response.ok) {
235-
// make the promise be rejected if we didn't get a 2xx response
244+
// reject the promise if we didn't get a 2xx response
236245
throw new Error("Unable to fetch IPS", {cause: response});
237246
} else {
238247
return response;

src/lib/resourceUploader.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const allowableResourceTypes = [
1919
'Consent',
2020
'Condition',
2121
'Immunization',
22-
// 'Procedure', Removed until hapi server thymeleaf fixes are available
22+
'Procedure', // Removed until hapi server thymeleaf fixes are available
2323
'Observation',
2424
'DiagnosticReport',
2525
'MedicationRequest',
@@ -71,7 +71,10 @@ export async function uploadResources(resources) {
7171
},
7272
body: JSON.stringify(bundle),
7373
}).then((response) => {
74-
return response.json()
74+
if (!response.ok) {
75+
throw new Error('Error uploading resources', { cause: response });
76+
}
77+
return response.json();
7578
}).then((body) => {
7679
let ipsUrl = "";
7780
body.entry.forEach(entry => {

0 commit comments

Comments
 (0)