File tree Expand file tree Collapse file tree 1 file changed +8
-10
lines changed
Expand file tree Collapse file tree 1 file changed +8
-10
lines changed Original file line number Diff line number Diff line change 33
44from fastapi import APIRouter , File , UploadFile , HTTPException
55from sqlmodel import select , update , and_
6+ from sqlalchemy .exc import NoResultFound , MultipleResultsFound
67
78from app .api .deps import CurrentUser , SessionDep
89from app .core .cloud import AmazonCloudStorage
@@ -92,17 +93,14 @@ def doc_info(
9293 select (Document )
9394 .where (Document .id == doc_id )
9495 )
95- docs = (session
96- .exec (statement )
97- .all ())
98- n = len (docs )
99- if n == 1 :
100- return docs [0 ]
101-
102- (status_code , reason ) = (500 , 'not unique' ) if n else (400 , 'not found' )
103- detail = f'Document "{ doc_id } " { reason } '
96+ result = session .exec (statement )
10497
105- raise HTTPException (status_code = status_code , detail = detail )
98+ try :
99+ return result .one ()
100+ except NoResultFound as err :
101+ raise HTTPException (status_code = 404 , detail = str (err ))
102+ except MultipleResultsFound as err :
103+ raise HTTPException (status_code = 500 , detail = str (err ))
106104
107105# @router.get("/assign", response_model=DocumentList)
108106# def assign_doc(
You can’t perform that action at this time.
0 commit comments