From 5b7a28684a5138f10e2dce1018b31570fc9d0c05 Mon Sep 17 00:00:00 2001 From: petitminion Date: Wed, 16 Mar 2022 12:54:35 +0000 Subject: [PATCH] Catch ValueError at the end of a radio --- api/funkwhale_api/radios/views.py | 7 ++++++- changes/changelog.d/catch_value_error_radio-bugfix | 1 + front/src/main.js | 5 +++++ front/src/store/radios.js | 3 ++- 4 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 changes/changelog.d/catch_value_error_radio-bugfix diff --git a/api/funkwhale_api/radios/views.py b/api/funkwhale_api/radios/views.py index 3c8f41c91..b8c10f1f3 100644 --- a/api/funkwhale_api/radios/views.py +++ b/api/funkwhale_api/radios/views.py @@ -137,7 +137,12 @@ class RadioSessionTrackViewSet(mixins.CreateModelMixin, viewsets.GenericViewSet) ) except AssertionError: return Response(status=status.HTTP_403_FORBIDDEN) - session.radio.pick() + try: + session.radio.pick() + except ValueError: + return Response( + "Radio doesn't have more candidates", status=status.HTTP_404_NOT_FOUND + ) session_track = session.session_tracks.all().latest("id") # self.perform_create(serializer) # dirty override here, since we use a different serializer for creation and detail diff --git a/changes/changelog.d/catch_value_error_radio-bugfix b/changes/changelog.d/catch_value_error_radio-bugfix new file mode 100644 index 000000000..2e6e74b7b --- /dev/null +++ b/changes/changelog.d/catch_value_error_radio-bugfix @@ -0,0 +1 @@ +Catch ValueError on radio end (#1596) diff --git a/front/src/main.js b/front/src/main.js index ef620fc94..2ff982fc0 100644 --- a/front/src/main.js +++ b/front/src/main.js @@ -99,6 +99,11 @@ axios.interceptors.response.use(function (response) { } if (error.response.status === 404) { error.backendErrors.push('Resource not found') + const message = error.response.data + store.commit('ui/addMessage', { + content: message, + class: 'error' + }) } else if (error.response.status === 403) { error.backendErrors.push('Permission denied') } else if (error.response.status === 429) { diff --git a/front/src/store/radios.js b/front/src/store/radios.js index 06f5ee2da..970a9c99d 100644 --- a/front/src/store/radios.js +++ b/front/src/store/radios.js @@ -97,8 +97,9 @@ export default { dispatch('queue/last', null, { root: true }) }) } - }, (response) => { + }, () => { logger.default.error('Error while adding track to queue from radio') + commit('reset') }) } }