diff --git a/src/main.py b/src/main.py index 1df6b16..dce83ab 100644 --- a/src/main.py +++ b/src/main.py @@ -1,5 +1,6 @@ import json import logging +import traceback import uuid from pathlib import Path from typing import Annotated @@ -157,21 +158,28 @@ async def solve( async with AsyncStealthySession(**kwargs) as engine: result = await engine.fetch(payload.url, page_action=make_page_action(payload)) + except Exception as e: + traceback.print_exc() + result_payload = { + "error": str(e), + "status": False + } + else: + status = not "error" in result["actions"][-1] + error = ["Something error", None][status] + + result_payload = { + "status": ["err", "ok"][status], + "user_agent": result["user_agent"], + "cookies": result["cookies"], + "actions": result["actions"], + } + if payload.html: + result_payload["html"] = result["html"] + if error: + result_payload["error"] = error finally: BROWSER_SLOTS += 1 - status = not "error" in result["actions"][-1] - error = ["Something error", None][status] - - result_payload = { - "status": ["err", "ok"][status], - "user_agent": result["user_agent"], - "cookies": result["cookies"], - "actions": result["actions"], - } - if payload.html: - result_payload["html"] = result["html"] - if error: - result_payload["error"] = error logger.info("Outgoing payload:\n%s", json.dumps(result_payload, indent=2, sort_keys=True, ensure_ascii=True)) return result_payload