From 61632c71439e01e1cad8bba81199ec89b84bf25f Mon Sep 17 00:00:00 2001 From: Ali Parlakci Date: Mon, 23 Jul 2018 23:33:11 +0300 Subject: [PATCH] Improve error handling --- src/downloader.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/downloader.py b/src/downloader.py index 88775e1..705e259 100644 --- a/src/downloader.py +++ b/src/downloader.py @@ -4,6 +4,7 @@ import sys import urllib.request from html.parser import HTMLParser from pathlib import Path +from urllib.error import HTTPError import imgurpython from multiprocessing import Queue @@ -72,15 +73,10 @@ def getFile(fileDir,tempDir,imageURL,indent=0): class Erome: def __init__(self,directory,post): - # try: - # IMAGES = self.getLinks(post['postURL']) - # except IndexError: - # # raise NotADownloadableLinkError("Could not read the page source") - # pass - # except Exception as exception: - # pass - # # raise NotADownloadableLinkError("Could not read the page source") - IMAGES = self.getLinks(post['postURL']) + try: + IMAGES = self.getLinks(post['postURL']) + except urllib.error.HTTPError: + raise NotADownloadableLinkError("Not a downloadable link") imagesLenght = len(IMAGES) howManyDownloaded = imagesLenght