From 5fd8db8f43fb6841adb4e49a28dfcafc71698f19 Mon Sep 17 00:00:00 2001 From: Michiel Scholten Date: Mon, 5 Sep 2016 15:14:11 +0200 Subject: [PATCH] Catch connection timeouts and such --- digimarks.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/digimarks.py b/digimarks.py index a19d6b7..eefeb45 100644 --- a/digimarks.py +++ b/digimarks.py @@ -105,6 +105,11 @@ class Bookmark(db.Model): favicon = CharField(null=True) # Status code: 200 is OK, 404 is not found, for example (showing an error) + HTTP_CONNECTIONERROR = 0 + HTTP_OK = 200 + HTTP_MOVEDTEMPORARILY = 304 + HTTP_NOTFOUND = 404 + http_status = IntegerField(default=200) redirect_uri = None @@ -154,8 +159,11 @@ class Bookmark(db.Model): def set_status_code(self): """ Check the HTTP status of the url, as it might not exist for example """ - result = requests.head(self.url) - self.http_status = result.status_code + try: + result = requests.head(self.url) + self.http_status = result.status_code + except ConnectionError: + self.http_status = HTTP_CONNECTIONERROR return self.http_status def set_favicon(self):