Skip to content

Commit

Permalink
frontend - fix error handling related to API call, check for status
Browse files Browse the repository at this point in the history
  • Loading branch information
Amy Chen committed Feb 6, 2025
1 parent 534a996 commit 229ab9c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 20 deletions.
24 changes: 14 additions & 10 deletions patientsearch/src/js/containers/Logout.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ import { getUrlParameter } from "../helpers/utility";
import { useSettingContext } from "../context/SettingContextProvider";
import "../../styles/app.scss";


const isForbidden = getUrlParameter("forbidden");
// Error message, e.g. forbidden error
const AlertMessage = () => {
const appSettings = useSettingContext().appSettings;
if (!getUrlParameter("forbidden")) return ""; // look for forbidden message for now, can be others as well
if (!isForbidden) return ""; // look for forbidden message for now, can be others as well
const message =
appSettings && appSettings["FORBIDDEN_TEXT"]
? appSettings["FORBIDDEN_TEXT"]
Expand Down Expand Up @@ -41,15 +43,17 @@ render(
</Typography>
<AlertMessage></AlertMessage>
<br />
<Button
color="primary"
href="/home"
align="center"
variant="outlined"
size="large"
>
Click here to log in
</Button>
{!isForbidden &&
<Button
color="primary"
href="/home"
align="center"
variant="outlined"
size="large"
>
Click here to log in
</Button>
}
</div>
</Layout>,
document.getElementById("content")
Expand Down
11 changes: 1 addition & 10 deletions patientsearch/src/js/context/PatientListContextProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -1067,17 +1067,8 @@ export default function PatientListContextProvider({ children }) {
})
.catch((error) => {
console.log("Failed to retrieve data", error);
//unauthorized error
//display error message or redirect based on error status
handleErrorCallback(error);
setErrorMessage(
`Error retrieving data: ${
typeof error === "string"
? error
: error && error.status
? "Error status " + error.status
: error
}`
);
resolve(defaults);
});
});
Expand Down
4 changes: 4 additions & 0 deletions patientsearch/src/js/helpers/utility.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ export async function fetchData(url, params, errorCallback) {
console.log("no results returned ", results);
if (!results.ok) {
console.log("Error results ", results);
if (results && results.status) {
// raise error here to allow callee to catch it as needed
throw results;
}
const errorMessage =
json && json.message
? json.message
Expand Down

0 comments on commit 229ab9c

Please sign in to comment.