Skip to content

Commit

Permalink
Return "None" to request callbacks if an error is encountered
Browse files Browse the repository at this point in the history
  • Loading branch information
fuzeman committed Aug 4, 2014
1 parent 2e00554 commit aa444ec
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
4 changes: 4 additions & 0 deletions examples/playlists.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ def on_playlists(self, playlists):
print "=" * 25

def on_playlist(self, playlist):
if playlist is None:
print "Unable to retrieve playlist"
return

print playlist.name
print "-" * 25

Expand Down
13 changes: 11 additions & 2 deletions spotify/components/base.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
from requests_futures.sessions import FuturesSession
import logging

USER_AGENT = 'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1941.0 Safari/537.36'

log = logging.getLogger(__name__)


class Component(object):
def __init__(self, sp=None):
Expand Down Expand Up @@ -35,7 +38,13 @@ def send_message(self, message):

@staticmethod
def request_wrapper(request, callback=None):
return request.on(
'success', callback,
def on_error(*args):
log.debug('Error %s returned for request: %s', repr(args), request)

if callback:
callback(None)

return request.on('success', callback).on(
'error', on_error,
on_bound=lambda: request.send()
)
10 changes: 10 additions & 0 deletions spotify/mercury/request.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from spotify.core.helpers import repr_trim
from spotify.core.request import Request
from spotify.core.uri import Uri
from spotify.objects import Parser
Expand Down Expand Up @@ -265,3 +266,12 @@ def cached_response(self, request):

def update_response(self, index, header, content_type, internal):
self.response[internal.gid] = (content_type, internal)

def __repr__(self):
return "<%s uris: %s>" % (
self.__class__.__name__,
repr_trim([r.get('uri') for r in self.requests])
)

def __str__(self):
return self.__repr__()

0 comments on commit aa444ec

Please sign in to comment.