diff --git a/backend/apps/web/routers/documents.py b/backend/apps/web/routers/documents.py index 9cc0dd5d1..c64ee8f06 100644 --- a/backend/apps/web/routers/documents.py +++ b/backend/apps/web/routers/documents.py @@ -49,13 +49,13 @@ async def create_new_doc(form_data: DocumentForm, user=Depends(get_current_user) return doc else: raise HTTPException( - status_code=status.HTTP_401_UNAUTHORIZED, - detail=ERROR_MESSAGES.DEFAULT(), + status_code=status.HTTP_400_BAD_REQUEST, + detail=ERROR_MESSAGES.FILE_EXISTS, ) else: raise HTTPException( status_code=status.HTTP_400_BAD_REQUEST, - detail=ERROR_MESSAGES.COMMAND_TAKEN, + detail=ERROR_MESSAGES.NAME_TAG_TAKEN, ) diff --git a/backend/constants.py b/backend/constants.py index b923ec8ba..c9bfaec5a 100644 --- a/backend/constants.py +++ b/backend/constants.py @@ -18,6 +18,8 @@ class ERROR_MESSAGES(str, Enum): "Uh-oh! This username is already registered. Please choose another username." ) COMMAND_TAKEN = "Uh-oh! This command is already registered. Please choose another command string." + FILE_EXISTS = "Uh-oh! This file is already registered. Please choose another file." + NAME_TAG_TAKEN = "Uh-oh! This name tag is already registered. Please choose another name tag string." INVALID_TOKEN = ( "Your session has expired or the token is invalid. Please sign in again." diff --git a/src/routes/(app)/documents/+page.svelte b/src/routes/(app)/documents/+page.svelte index fa290999a..63c7cb50f 100644 --- a/src/routes/(app)/documents/+page.svelte +++ b/src/routes/(app)/documents/+page.svelte @@ -29,7 +29,10 @@ }; const uploadDoc = async (file) => { - const res = await uploadDocToVectorDB(localStorage.token, '', file); + const res = await uploadDocToVectorDB(localStorage.token, '', file).catch((error) => { + toast.error(error); + return null; + }); if (res) { await createNewDoc( @@ -38,7 +41,10 @@ res.filename, transformFileName(res.filename), res.filename - ); + ).catch((error) => { + toast.error(error); + return null; + }); await documents.set(await getDocs(localStorage.token)); } };