Skip to content
This repository has been archived by the owner on Jan 19, 2020. It is now read-only.

Commit

Permalink
Custom downloader exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
Makoto committed Mar 9, 2016
1 parent 10fc77c commit f891f85
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
7 changes: 6 additions & 1 deletion tumdlr/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from hashlib import md5

from tumdlr.downloader import sanitize_filename, download
from tumdlr.errors import TumblrDownloadError


class TumblrPost:
Expand Down Expand Up @@ -176,7 +177,11 @@ def download(self, context, **kwargs):
Returns:
str: Path to the saved file
"""
download(self.url.as_string(), str(self.filepath(context, kwargs)), **kwargs)
try:
download(self.url.as_string(), str(self.filepath(context, kwargs)), **kwargs)
except Exception as e:
self.log.warn('Post download failed: {}'.format(repr(self)), exc_info=e)
raise TumblrDownloadError(error_message=str(e), download_url=self.url.as_string())

def filepath(self, context, request_data):
"""
Expand Down
16 changes: 16 additions & 0 deletions tumdlr/errors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class TumdlrException(Exception):
pass


###############################
# Begin file container errors #
###############################
class TumblrFileError(TumdlrException):
pass


class TumblrDownloadError(TumblrFileError):
def __init__(self, *args, **kwargs):
self.download_url = kwargs.get('download_url')
self.error_message = kwargs.get('error_message')
super().__init__('An error occurred while downloading a file entry from a post')

0 comments on commit f891f85

Please sign in to comment.