enhance error handling for browser initialization and cleanup processes
Build and Push Docker Images / build-and-push (push) Successful in 17s

This commit is contained in:
2025-03-31 14:50:11 +02:00
parent ab715342b1
commit 6db86a176b
+6 -1
View File
@@ -128,6 +128,8 @@ async def visit_url(url: str, x_api_key: Optional[str] = Header(None), backgroun
# Get browser instance # Get browser instance
browser_instance = await get_browser() browser_instance = await get_browser()
if browser_instance is None:
raise HTTPException(status_code=500, detail="Failed to initialize browser")
# Create new page # Create new page
page = await browser_instance.newPage() page = await browser_instance.newPage()
@@ -156,7 +158,10 @@ async def visit_url(url: str, x_api_key: Optional[str] = Header(None), backgroun
logger.error(f"Error processing request: {str(e)}") logger.error(f"Error processing request: {str(e)}")
# Ensure cleanup happens even on error # Ensure cleanup happens even on error
if page: if page:
await cleanup_resources(page, False) try:
await cleanup_resources(page, False)
except Exception as cleanup_error:
logger.error(f"Error during error cleanup: {str(cleanup_error)}")
raise HTTPException(status_code=500, detail=str(e)) raise HTTPException(status_code=500, detail=str(e))
@app.on_event("shutdown") @app.on_event("shutdown")