add gracefull errors

This commit is contained in:
Thephaseless 2024-07-25 21:00:11 +00:00
parent 24a0271a04
commit af4750a52a

View File

@ -12,9 +12,7 @@ from src.models.requests import LinkRequest, LinkResponse
from src.utils import logger from src.utils import logger
from src.utils.browser import bypass_cloudflare, new_browser from src.utils.browser import bypass_cloudflare, new_browser
from src.utils.consts import LOG_LEVEL from src.utils.consts import LOG_LEVEL
from src.utils.extentions import download_extentions
download_extentions()
app = FastAPI(debug=True) app = FastAPI(debug=True)
@ -32,6 +30,7 @@ async def read_item(request: LinkRequest):
logger.info(f"Request: {request}") logger.info(f"Request: {request}")
start_time = int(time.time() * 1000) start_time = int(time.time() * 1000)
browser = await new_browser() browser = await new_browser()
try:
page = await browser.get(request.url) page = await browser.get(request.url)
await page.bring_to_front() await page.bring_to_front()
@ -46,6 +45,9 @@ async def read_item(request: LinkRequest):
start_timestamp=start_time, start_timestamp=start_time,
challenged=challenged, challenged=challenged,
) )
except asyncio.TimeoutError:
logger.fatal("Couldn't complete the request")
finally:
browser.stop() browser.stop()
return response return response