force exit on exception

This commit is contained in:
Thephaseless 2024-12-10 21:29:20 +00:00
parent 04a8433dda
commit 3860beec84

14
main.py
View File

@ -53,8 +53,8 @@ def read_item(request: LinkRequest):
response: LinkResponse response: LinkResponse
# start_time = int(time.time() * 1000) # start_time = int(time.time() * 1000)
try: with SB(uc=True, locale_code="en", test=False, xvfb=True, ad_block=True) as sb:
with SB(uc=True, locale_code="en", test=False, xvfb=True, ad_block=True) as sb: try:
sb: BaseCase sb: BaseCase
sb.uc_open_with_reconnect(request.url) sb.uc_open_with_reconnect(request.url)
source = sb.get_page_source() source = sb.get_page_source()
@ -86,9 +86,13 @@ def read_item(request: LinkRequest):
), ),
startTimestamp=start_time, startTimestamp=start_time,
) )
except Exception as e: except Exception as e:
logger.error(f"Error: {e}") logger.error(f"Error: {e}")
raise HTTPException(status_code=500, detail="Unknown error, check logs") from e if sb.driver:
sb.driver.quit()
raise HTTPException(
status_code=500, detail="Unknown error, check logs"
) from e
return response return response