Skip to content

Commit 19d8f4d

Browse files
committed
🛠️ fix: Improve HTTP Exception Logging Across Multiple Routes
1 parent fb5d330 commit 19d8f4d

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

main.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,13 @@ async def get_all_ids():
114114
ids = vector_store.get_all_ids()
115115

116116
return list(set(ids))
117+
except HTTPException as http_exc:
118+
logger.error(
119+
"HTTP Exception in get_all_ids | Status: %d | Detail: %s",
120+
http_exc.status_code,
121+
http_exc.detail,
122+
)
123+
raise http_exc
117124
except Exception as e:
118125
logger.error(
119126
"Failed to get all IDs | Error: %s | Traceback: %s",
@@ -204,6 +211,13 @@ async def delete_documents(document_ids: List[str] = Body(...)):
204211
return {
205212
"message": f"Documents for {file_count} file{'s' if file_count > 1 else ''} deleted successfully"
206213
}
214+
except HTTPException as http_exc:
215+
logger.error(
216+
"HTTP Exception in delete_documents | Status: %d | Detail: %s",
217+
http_exc.status_code,
218+
http_exc.detail,
219+
)
220+
raise http_exc
207221
except Exception as e:
208222
logger.error(
209223
"Failed to delete documents | IDs: %s | Error: %s | Traceback: %s",
@@ -275,6 +289,13 @@ async def query_embeddings_by_file_id(
275289

276290
return authorized_documents
277291

292+
except HTTPException as http_exc:
293+
logger.error(
294+
"HTTP Exception in query_embeddings_by_file_id | Status: %d | Detail: %s",
295+
http_exc.status_code,
296+
http_exc.detail,
297+
)
298+
raise http_exc
278299
except Exception as e:
279300
logger.error(
280301
"Error in query embeddings | File ID: %s | Query: %s | Error: %s | Traceback: %s",
@@ -419,6 +440,13 @@ async def embed_local_file(
419440
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
420441
detail=ERROR_MESSAGES.DEFAULT(),
421442
)
443+
except HTTPException as http_exc:
444+
logger.error(
445+
"HTTP Exception in embed_local_file | Status: %d | Detail: %s",
446+
http_exc.status_code,
447+
http_exc.detail,
448+
)
449+
raise http_exc
422450
except Exception as e:
423451
logger.error(e)
424452
if "No pandoc was found" in str(e):
@@ -495,6 +523,15 @@ async def embed_file(
495523
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
496524
detail="An unspecified error occurred.",
497525
)
526+
except HTTPException as http_exc:
527+
response_status = False
528+
response_message = f"HTTP Exception: {http_exc.detail}"
529+
logger.error(
530+
"HTTP Exception in embed_file | Status: %d | Detail: %s",
531+
http_exc.status_code,
532+
http_exc.detail,
533+
)
534+
raise http_exc
498535
except Exception as e:
499536
response_status = False
500537
response_message = f"Error during file processing: {str(e)}"
@@ -551,6 +588,13 @@ async def load_document_context(id: str):
551588
)
552589

553590
return process_documents(documents)
591+
except HTTPException as http_exc:
592+
logger.error(
593+
"HTTP Exception in load_document_context | Status: %d | Detail: %s",
594+
http_exc.status_code,
595+
http_exc.detail,
596+
)
597+
raise http_exc
554598
except Exception as e:
555599
logger.error(
556600
"Error loading document context | Document ID: %s | Error: %s | Traceback: %s",
@@ -600,7 +644,20 @@ async def embed_file_upload(
600644
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
601645
detail="Failed to process/store the file data.",
602646
)
647+
except HTTPException as http_exc:
648+
logger.error(
649+
"HTTP Exception in embed_file_upload | Status: %d | Detail: %s",
650+
http_exc.status_code,
651+
http_exc.detail,
652+
)
653+
raise http_exc
603654
except Exception as e:
655+
logger.error(
656+
"Error during file processing | File: %s | Error: %s | Traceback: %s",
657+
uploaded_file.filename,
658+
str(e),
659+
traceback.format_exc(),
660+
)
604661
raise HTTPException(
605662
status_code=status.HTTP_400_BAD_REQUEST,
606663
detail=f"Error during file processing: {str(e)}",
@@ -644,6 +701,13 @@ async def query_embeddings_by_file_ids(body: QueryMultipleBody):
644701
)
645702

646703
return documents
704+
except HTTPException as http_exc:
705+
logger.error(
706+
"HTTP Exception in query_embeddings_by_file_ids | Status: %d | Detail: %s",
707+
http_exc.status_code,
708+
http_exc.detail,
709+
)
710+
raise http_exc
647711
except Exception as e:
648712
logger.error(
649713
"Error in query multiple embeddings | File IDs: %s | Query: %s | Error: %s | Traceback: %s",

0 commit comments

Comments
 (0)