Skip to content

Commit

Permalink
Redirect to error page if can't load request info
Browse files Browse the repository at this point in the history
  • Loading branch information
uoa-noel committed Dec 13, 2024
1 parent afb9083 commit 165d59a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
8 changes: 7 additions & 1 deletion web/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { formState, requestInfo } from './store';
import { client } from './client';
import { loadRequestInfo } from './client/requestInfo';
import { onErrorCaptured } from 'vue';
import router from './router';
window.addEventListener('beforeunload', (event) => {
// If the user has started the form but hasn't finished it, give a warning before
Expand All @@ -25,7 +26,12 @@ client.interceptors.request.use((request, _) => {
});
// Load initial request information - project and drive.
loadRequestInfo();
loadRequestInfo().then((hasLoadedRequestInfo: boolean) => {
if (!hasLoadedRequestInfo) {
// If loading the request info wasn't successful, redirect to error page.
router.replace("/service-error");
}
});
</script>

<template>
Expand Down
5 changes: 3 additions & 2 deletions web/src/client/requestInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,18 @@ async function getDrive(): Promise<ResearchDriveService> {
return project.research_drives[0];
}

export async function loadRequestInfo() {
export async function loadRequestInfo(): Promise<boolean> {
// Pre-populate archive request info.
try {
requestInfo.isLoading = true;
requestInfo.project = await getProject();
requestInfo.drive = await getDrive();
return true;
} catch (e) {
requestInfo.isLoading = false;
requestInfo.error = e;
// TODO redirect to error page.
console.error("Could not retrieve request information. Bad invite link?");
console.error(e);
return false;
}
}

0 comments on commit 165d59a

Please sign in to comment.