From b58a681484fb7d7377006102b023dedc3a7d26c9 Mon Sep 17 00:00:00 2001 From: dbarkowsky Date: Fri, 14 Jul 2023 15:00:36 -0700 Subject: [PATCH] Added more axios 401 catch cases --- .../custom/fileHandlers/FileLink.tsx | 18 ++++++++++++----- .../components/custom/forms/RequestForm.tsx | 18 ++++++++++++----- .../components/custom/modals/UserReport.tsx | 20 +++++++++++++------ app/src/pages/IndividualRequest.tsx | 18 ++++++++++++----- 4 files changed, 53 insertions(+), 21 deletions(-) diff --git a/app/src/components/custom/fileHandlers/FileLink.tsx b/app/src/components/custom/fileHandlers/FileLink.tsx index 6ea7f07..6de691d 100644 --- a/app/src/components/custom/fileHandlers/FileLink.tsx +++ b/app/src/components/custom/fileHandlers/FileLink.tsx @@ -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, + }); + } } }; diff --git a/app/src/components/custom/forms/RequestForm.tsx b/app/src/components/custom/forms/RequestForm.tsx index 476bd18..33a80ae 100644 --- a/app/src/components/custom/forms/RequestForm.tsx +++ b/app/src/components/custom/forms/RequestForm.tsx @@ -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, + }); + } } }; diff --git a/app/src/components/custom/modals/UserReport.tsx b/app/src/components/custom/modals/UserReport.tsx index 8bbedf0..155ff56 100644 --- a/app/src/components/custom/modals/UserReport.tsx +++ b/app/src/components/custom/modals/UserReport.tsx @@ -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, + }); + } } }; diff --git a/app/src/pages/IndividualRequest.tsx b/app/src/pages/IndividualRequest.tsx index 9fdd618..729bbb7 100644 --- a/app/src/pages/IndividualRequest.tsx +++ b/app/src/pages/IndividualRequest.tsx @@ -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, + }); + } } };