mirror of
https://github.com/ThePhaseless/Byparr.git
synced 2025-03-15 09:50:20 +08:00
add exception handling
This commit is contained in:
parent
f0d72ef56b
commit
9e1faedb1a
9
main.py
9
main.py
@ -6,7 +6,7 @@ import time
|
|||||||
|
|
||||||
import uvicorn
|
import uvicorn
|
||||||
import uvicorn.config
|
import uvicorn.config
|
||||||
from fastapi import FastAPI
|
from fastapi import FastAPI, HTTPException
|
||||||
from fastapi.responses import RedirectResponse
|
from fastapi.responses import RedirectResponse
|
||||||
|
|
||||||
from src.models.requests import LinkRequest, LinkResponse
|
from src.models.requests import LinkRequest, LinkResponse
|
||||||
@ -36,12 +36,15 @@ async def read_item(request: LinkRequest):
|
|||||||
timeout = request.maxTimeout
|
timeout = request.maxTimeout
|
||||||
if timeout == 0:
|
if timeout == 0:
|
||||||
timeout = None
|
timeout = None
|
||||||
|
try:
|
||||||
challenged = await asyncio.wait_for(bypass_cloudflare(page), timeout=timeout)
|
challenged = await asyncio.wait_for(bypass_cloudflare(page), timeout=timeout)
|
||||||
|
except asyncio.TimeoutError as e:
|
||||||
|
await page.save_screenshot("errors/error.png")
|
||||||
|
raise HTTPException(detail="Timeout", status_code=408) from e
|
||||||
|
|
||||||
logger.info(f"Got webpage: {request.url}")
|
logger.info(f"Got webpage: {request.url}")
|
||||||
|
|
||||||
response = await LinkResponse.create(
|
response = LinkResponse.create(
|
||||||
page=page,
|
page=page,
|
||||||
start_timestamp=start_time,
|
start_timestamp=start_time,
|
||||||
challenged=challenged,
|
challenged=challenged,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user