Skip to content

Instantly share code, notes, and snippets.

@Thewsomeguy
Forked from atiaxi/failable.py
Created December 16, 2015 02:54
Show Gist options
  • Save Thewsomeguy/a707ae42a8cca112a6d0 to your computer and use it in GitHub Desktop.
Save Thewsomeguy/a707ae42a8cca112a6d0 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