Skip to content

Commit

Permalink
Added more axios 401 catch cases
Browse files Browse the repository at this point in the history
  • Loading branch information
dbarkowsky committed Jul 14, 2023
1 parent 2de5057 commit b58a681
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 21 deletions.
18 changes: 13 additions & 5 deletions app/src/components/custom/fileHandlers/FileLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,19 @@ const FileLink = (props: FileLinkProps) => {
const file: string = await axios(axiosReqConfig).then((response) => response.data.file);
return file;
} catch (e: any) {
setErrorState({
text: 'File could not be retrieved.',
open: true,
style: errorStyles.error,
});
if (axios.isAxiosError(e) && e.code === '401') {
setErrorState({
text: 'User is unauthenticated. Redirecting to login.',
open: true,
});
window.location.reload();
} else {
setErrorState({
text: 'File could not be retrieved.',
open: true,
style: errorStyles.error,
});
}
}
};

Expand Down
18 changes: 13 additions & 5 deletions app/src/components/custom/forms/RequestForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,19 @@ const RequestForm = (props: RequestFormProps) => {
}
} catch (e) {
console.warn(e);
setErrorState({
text: 'Deletion Unsuccessful.',
open: true,
style: errorStyles.error,
});
if (axios.isAxiosError(e) && e.code === '401') {
setErrorState({
text: 'User is unauthenticated. Redirecting to login.',
open: true,
});
window.location.reload();
} else {
setErrorState({
text: 'Deletion Unsuccessful.',
open: true,
style: errorStyles.error,
});
}
}
};

Expand Down
20 changes: 14 additions & 6 deletions app/src/components/custom/modals/UserReport.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,20 @@ export const UserReport = () => {
}
} catch (e) {
console.warn(e);
// Request failed. Report error to user.
setErrorState({
text: 'Issue could not be submitted.',
open: true,
style: errorStyles.error,
});
if (axios.isAxiosError(e) && e.code === '401') {
setErrorState({
text: 'User is unauthenticated. Redirecting to login.',
open: true,
});
window.location.reload();
} else {
// Request failed. Report error to user.
setErrorState({
text: 'Issue could not be submitted.',
open: true,
style: errorStyles.error,
});
}
}
};

Expand Down
18 changes: 13 additions & 5 deletions app/src/pages/IndividualRequest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,19 @@ const IndividualRequest = () => {
}
} catch (e) {
console.warn('Record could not be updated.');
setErrorState({
text: 'Update was unsuccessful.',
open: true,
style: errorStyles.error,
});
if (axios.isAxiosError(e) && e.code === '401') {
setErrorState({
text: 'User is unauthenticated. Redirecting to login.',
open: true,
});
window.location.reload();
} else {
setErrorState({
text: 'Update was unsuccessful.',
open: true,
style: errorStyles.error,
});
}
}
};

Expand Down

0 comments on commit b58a681

Please sign in to comment.