Skip to content

Commit

Permalink
Merge pull request #921 from Inter-Actief/903-jsondecodeerror-at-narr…
Browse files Browse the repository at this point in the history
…owcastingroompause_spotify

Longer spotify caching and disabled logging for spotify rate limit exceeded
  • Loading branch information
supertom01 authored Feb 3, 2025
2 parents caf7dd6 + 005df50 commit 7a17acc
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions amelie/narrowcasting/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def _spotify_refresh_token(association):
raise e
return association

@cache_page(5)
@cache_page(15)
def room_spotify_now_playing(request):
identifier = request.GET.get('id', None)
if settings.SPOTIFY_CLIENT_SECRET == "":
Expand Down Expand Up @@ -142,13 +142,16 @@ def room_spotify_now_playing(request):
return room_spotify_now_playing(request)
except ValueError as e:
data = {'error': True, 'code': 500, 'msg': str(e)}
elif res.status_code == 429:
# Since we often exceed the rate limit, do not report as error
data = {'error': False, 'is_playing': False}
else:
data = {'error': True, 'code': res.status_code, 'msg': res.content.decode()}

return JsonResponse(data)


@cache_page(5)
@cache_page(15)
def room_spotify_pause(request):
identifier = request.GET.get('id', None)
if settings.SPOTIFY_CLIENT_SECRET == "":
Expand Down Expand Up @@ -184,13 +187,16 @@ def room_spotify_pause(request):
return room_spotify_pause(request)
except ValueError as e:
data = {'error': True, 'code': 500, 'msg': str(e)}
elif res.status_code == 429:
# Since we often exceed the rate limit, do not report as error
data = {'error': False, 'is_playing': False}
else:
data = {'error': True, 'code': res.status_code, 'msg': res.content.decode()}

return JsonResponse(data)


@cache_page(5)
@cache_page(15)
def room_spotify_play(request):
identifier = request.GET.get('id', None)
if settings.SPOTIFY_CLIENT_SECRET == "":
Expand Down Expand Up @@ -226,7 +232,11 @@ def room_spotify_play(request):
return room_spotify_play(request)
except ValueError as e:
data = {'error': True, 'code': 500, 'msg': str(e)}
elif res.status_code == 429:
# Since we often exceed the rate limit, do not report as error
data = {'error': False, 'is_playing': False}
else:
data = {'error': True, 'code': res.status_code, 'msg': res.content.decode()}


return JsonResponse(data)

0 comments on commit 7a17acc

Please sign in to comment.