Merge pull request #432 from facetoe/exceptions
Catch some common exceptions
This commit is contained in:
commit
3fcfb88084
@ -1,8 +1,11 @@
|
||||
from i3pystatus import IntervalModule
|
||||
import requests
|
||||
import json
|
||||
|
||||
import requests
|
||||
from i3pystatus import IntervalModule
|
||||
from i3pystatus import logger
|
||||
from i3pystatus.core import ConfigError
|
||||
from i3pystatus.core.util import user_open, internet, require
|
||||
from requests import Timeout, ConnectionError
|
||||
|
||||
|
||||
class Github(IntervalModule):
|
||||
@ -51,19 +54,23 @@ class Github(IntervalModule):
|
||||
|
||||
@require(internet)
|
||||
def run(self):
|
||||
format_values = dict(unread_count='', unread='')
|
||||
|
||||
if self.access_token:
|
||||
response = requests.get('https://api.github.com/notifications?access_token=' + self.access_token)
|
||||
else:
|
||||
response = requests.get('https://api.github.com/notifications', auth=(self.username, self.password))
|
||||
data = json.loads(response.text)
|
||||
try:
|
||||
if self.access_token:
|
||||
response = requests.get('https://api.github.com/notifications?access_token=' + self.access_token)
|
||||
else:
|
||||
response = requests.get('https://api.github.com/notifications', auth=(self.username, self.password))
|
||||
data = json.loads(response.text)
|
||||
except (ConnectionError, Timeout) as e:
|
||||
logger.warn(e)
|
||||
data = []
|
||||
|
||||
# Bad credentials
|
||||
if isinstance(data, dict):
|
||||
err_msg = data['message']
|
||||
raise ConfigError(err_msg)
|
||||
|
||||
format_values = dict(unread_count='', unread='')
|
||||
unread = len(data)
|
||||
if unread > 0:
|
||||
format_values['unread_count'] = unread
|
||||
|
@ -6,7 +6,6 @@ import pytz
|
||||
from apiclient import discovery
|
||||
from dateutil import parser
|
||||
from googleapiclient.errors import HttpError
|
||||
|
||||
from i3pystatus import IntervalModule, logger
|
||||
from i3pystatus.core.color import ColorRangeModule
|
||||
from i3pystatus.core.util import internet, require, user_open
|
||||
@ -70,7 +69,11 @@ class GoogleCalendar(IntervalModule, ColorRangeModule):
|
||||
if not self.service:
|
||||
self.connect_service()
|
||||
|
||||
self.display_event = self.get_next_event()
|
||||
try:
|
||||
self.display_event = self.get_next_event()
|
||||
except ConnectionResetError as e:
|
||||
logger.warn(e)
|
||||
|
||||
if self.display_event:
|
||||
start_time = self.display_event['start_time']
|
||||
now = datetime.datetime.now(tz=pytz.UTC)
|
||||
|
Loading…
Reference in New Issue
Block a user