enhance error handling for browser initialization and cleanup processes
Build and Push Docker Images / build-and-push (push) Successful in 17s
Build and Push Docker Images / build-and-push (push) Successful in 17s
This commit is contained in:
@@ -128,6 +128,8 @@ async def visit_url(url: str, x_api_key: Optional[str] = Header(None), backgroun
|
||||
|
||||
# Get browser instance
|
||||
browser_instance = await get_browser()
|
||||
if browser_instance is None:
|
||||
raise HTTPException(status_code=500, detail="Failed to initialize browser")
|
||||
|
||||
# Create new page
|
||||
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)}")
|
||||
# Ensure cleanup happens even on error
|
||||
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))
|
||||
|
||||
@app.on_event("shutdown")
|
||||
|
||||
Reference in New Issue
Block a user