From b287ac92fe6c02d80445f4a1070c12d9f9cb7644 Mon Sep 17 00:00:00 2001 From: xrando <2837341L@student.gla.ac.uk> Date: Sun, 29 Oct 2023 16:57:30 +0800 Subject: [PATCH] modified error msg on frontend modified error msg on frontend --- .../safeshare-frontend/src/pages/shareFile.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/safeshare/safeshare-frontend/src/pages/shareFile.js b/safeshare/safeshare-frontend/src/pages/shareFile.js index ce68ce8..60b1724 100644 --- a/safeshare/safeshare-frontend/src/pages/shareFile.js +++ b/safeshare/safeshare-frontend/src/pages/shareFile.js @@ -9,10 +9,10 @@ function ShareFile() { const [ttl, setTtl] = useState(''); const [shareableLink, setShareableLink] = useState(''); const [notification, setNotification] = useState(''); + const [errorMessage, setErrorMessage] = useState(''); const handleFileUpload = (file) => { setFile(file); - //setPasscode('1234'); console.log(file); if (file) { const formData = new FormData(); @@ -43,6 +43,11 @@ function ShareFile() { .catch((error) => { // Handle errors here console.error('File upload failed', error); + if (error.response && error.response.status === 400) { + setErrorMessage('File uploaded is suspected to contain virus'); + } else { + setErrorMessage('An unexpected error occurred. Please try again.'); + } }); } }; @@ -104,6 +109,13 @@ function ShareFile() { )} + {errorMessage && ( +