Skip to content

Commit

Permalink
Fixed issue with request_wrapper() when used as a decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
fuzeman committed Aug 4, 2014
1 parent c77d78b commit cc14a20
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions spotify/components/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,20 @@ def send_message(self, message):

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

if callback:
callback(None)
if func:
func(None)

return request.on('success', callback).on(
'error', on_error,
on_bound=lambda: request.send()
def on_bound(func):
# Bind to 'error' (so we know the real callback 'func')
request.on('error', lambda *args: on_error(func, *args))

# Send request
request.send()

return request.on(
'success', callback,
on_bound=on_bound
)

0 comments on commit cc14a20

Please sign in to comment.