Skip to content

Commit

Permalink
Merge pull request #8 from uwcirg/feature/viewer-errors
Browse files Browse the repository at this point in the history
Feature/viewer errors
  • Loading branch information
daniellrgn authored Apr 1, 2024
2 parents 4f6e6e8 + 049252c commit 45da735
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 16 deletions.
69 changes: 56 additions & 13 deletions static/view/assets/js/retreiveIPS.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,70 @@ if (shl) {
try {
retrieve()
} catch (e) {
console.error("Unable to retrieve SHL: " + e);

console.error("Unable to load Report: " + e);
$("#error").html("There was a problem loading this report. Please ensure this link is active before trying again.");
$("#status").hide();
$("#ips-loader").hide();
}
}

async function retrieve(){
const recipient = "WA Verify+ IPS Viewer";
const recipient = "LTT Choices Report Viewer";

let passcode;
const needPasscode = shlClient.flag({ shl}).includes('P');
const needPasscode = shlClient.flag({ shl }).includes('P');
if (needPasscode) {
passcode = prompt("Enter passcode for SMART Health Link");
passcode = prompt("Enter passcode to view this Choices Report");
}
$('#status').text("Retrieving contents...");
let retrieveResult;
try {
retrieveResult = await shlClient.retrieve({
shl,
passcode,
recipient
});
} catch (e) {
// Retrieval succeeded, but there was an error parsing files, etc.
console.log(e);
throw Error("Content parsing error");
}

const retrieved = await shlClient.retrieve({
shl,
passcode,
recipient
});

const decoded = await Promise.all(retrieved.shcs.map(verify));
if ("error" in retrieveResult) {
let errorMsg = "";
if (retrieveResult.status) {
if (retrieveResult.status === 404) {
// Couldn't find the shl, or it has been deactivated
errorMsg = `<p>This link to view a Choices Report does not exist or has been deactivated.</p>`;
} else if (retrieveResult.status === 401) {
// Failed the password requirement
while (retrieveResult.status === 401) {
passcode = prompt(`Enter passcode to view this Choices Report ${retrieveResult.error.remainingAttempts !== undefined ? "\nAttempts remaining: "+retrieveResult.error.remainingAttempts : ""}`);
try {
retrieveResult = await shlClient.retrieve({
shl,
passcode,
recipient
});
} catch {
// Retrieval succeeded, but there was an error parsing files etc.
console.log(e);
throw Error("Content parsing error");
}
}
if (!retrieveResult.ok) {
const managerLink = `<a href="${new URL(import.meta.url).origin}/view/${shlClient.id({ shl })}">Manage or reactivate it here</a>`;
errorMsg = `<p>This link to the requested Choices Report has been deactivated due to too many failed password attempts.</p><p>Are you the owner of this link? ${managerLink}</p>`;
}
} else {
errorMsg = retrieveResult.error;
}
}
$("#error").html(`${errorMsg}`);
$("#ips-loader").hide();
return;
}
const decoded = await Promise.all(retrieveResult.shcs.map(verify));
const data = decoded.map((e) => e.fhirBundle);
prepareSHLContents(data);
}
}
9 changes: 6 additions & 3 deletions static/view/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,13 @@

<body>
<div id="content" style="display:none; padding: auto; margin:auto" class="main container-fluid">
<!-- IPS Default Header for Connectathons -->
<!-- Removing header id element will remove header -->
<!-- <div style="padding: 28px"></div> -->
<div style="padding-left: 17px;" class="row">
<p id="error"></p>
</div>
<div id="ips-loader" class="row">
<div style="margin-left: 38px;" class="row">
<p id="status"></p>
</div>
<span class="loader"></span>
</div>
<div id="rendered-ips" class="ml-4 mt-0 ml-sm-4 mt-sm-4">
Expand Down

0 comments on commit 45da735

Please sign in to comment.