Skip to content

Instantly share code, notes, and snippets.

@atiaxi
Last active September 7, 2016 04:47
Show Gist options
  • Save atiaxi/fd7d5e6c3f83d785d7cf to your computer and use it in GitHub Desktop.
Save atiaxi/fd7d5e6c3f83d785d7cf to your computer and use it in GitHub Desktop.
import praw
from requests.exceptions import ConnectionError, HTTPError, Timeout
def failable(f):
def wrapped(*args, **kwargs):
try:
return f(*args, **kwargs)
except praw.errors.APIException:
full = traceback.format_exc()
logging.warning("Reddit API call failed! %s" % full)
return None
except ConnectionError:
full = traceback.format_exc()
logging.warning("Connection error: %s", full)
except (Timeout, socket.timeout, socket.error):
full = traceback.format_exc()
logging.warning("Socket timeout! %s" % full)
return None
except HTTPError:
full = traceback.format_exc()
logging.warning("HTTP error %s" % full)
return None
return wrapped
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment