discogs: Catch *another* exception (fix #1305)

Everything but requests is a travesty.
This commit is contained in:
Adrian Sampson 2015-02-03 23:04:14 -08:00
parent a7878b0eba
commit cc01d87209
2 changed files with 8 additions and 4 deletions

View file

@ -31,6 +31,7 @@ import re
import time
import json
import socket
import httplib
# Silence spurious INFO log lines generated by urllib3.
@ -39,6 +40,9 @@ urllib3_logger.setLevel(logging.CRITICAL)
USER_AGENT = u'beets/{0} +http://beets.radbox.org/'.format(beets.__version__)
# Exceptions that discogs_client should really handle but does not.
CONNECTION_ERRORS = ConnectionError, socket.error, httplib.HTTPException
class DiscogsPlugin(BeetsPlugin):
@ -91,7 +95,7 @@ class DiscogsPlugin(BeetsPlugin):
token, secret = auth_client.get_access_token(code)
except DiscogsAPIError:
raise beets.ui.UserError('Discogs authorization failed')
except (ConnectionError, socket.error) as e:
except CONNECTION_ERRORS as e:
self._log.debug(u'connection error: {0}', e)
raise beets.ui.UserError('communication with Discogs failed')
@ -126,7 +130,7 @@ class DiscogsPlugin(BeetsPlugin):
except DiscogsAPIError as e:
self._log.debug(u'API Error: {0} (query: {1})', e, query)
return []
except (ConnectionError, socket.error) as e:
except CONNECTION_ERRORS as e:
self._log.debug(u'HTTP Connection Error: {0}', e)
return []
@ -154,7 +158,7 @@ class DiscogsPlugin(BeetsPlugin):
if e.message != '404 Not Found':
self._log.debug(u'API Error: {0} (query: {1})', e, result._uri)
return None
except ConnectionError as e:
except CONNECTION_ERRORS as e:
self._log.debug(u'HTTP Connection Error: {0}', e)
return None
return self.get_album_info(result)

View file

@ -100,7 +100,7 @@ Fixes:
scrub`` command cannot write a file. Also, avoid problems on Windows with
Unicode filenames. :bug:`1297`
* :doc:`/plugins/discogs`: Handle and log more kinds of communication
errors. :bug:`1299`
errors. :bug:`1299` :bug:`1305`
For developers: