From a2d691dbf9ecd29cbbaaef26f22a4cfb3951bd43 Mon Sep 17 00:00:00 2001 From: Michel Roux Date: Sun, 22 Mar 2020 17:53:50 +0100 Subject: [PATCH] Better error handling --- app.py | 8 +++++--- connectors.py | 3 +-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/app.py b/app.py index 4e96738..7c8f5c2 100644 --- a/app.py +++ b/app.py @@ -1,5 +1,6 @@ -import time +from logging import getLogger from operator import attrgetter, itemgetter +from time import sleep from flask import redirect, render_template, request, url_for @@ -182,6 +183,7 @@ if __name__ == '__main__': while True: try: app.run('0.0.0.0', APP_PORT, IS_DEBUG) - except Exception: - time.sleep(10) + except Exception as e: + getLogger().exception(e) + sleep(10) pass diff --git a/connectors.py b/connectors.py index 0128cfe..0aedf80 100644 --- a/connectors.py +++ b/connectors.py @@ -10,7 +10,6 @@ from urllib.parse import quote import requests from bs4 import BeautifulSoup -from requests import Timeout from config import IS_DEBUG, CACHE_TIMEOUT, BLACKLIST_WORDS from models import AnimeLink @@ -164,7 +163,7 @@ class Connector(ABC): output = response.text http_code = response.status_code - except Timeout as e: + except requests.Timeout as e: output = '' http_code = 500 if IS_DEBUG: