From 4a2dc9c73e17a5901dca808d3f766659cb522b94 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Thu, 28 May 2020 16:51:48 +0200 Subject: [PATCH] Raise ExternalError for 400+ response in funkwhale --- publish.bat | 2 +- royalpack/commands/funkwhale.py | 2 ++ royalpack/commands/funkwhalealbum.py | 2 ++ royalpack/commands/funkwhaleplaylist.py | 4 ++++ royalpack/commands/lazyfunkwhale.py | 2 ++ royalpack/commands/lazyfunkwhalealbum.py | 2 ++ royalpack/commands/lazyfunkwhaleplaylist.py | 4 ++++ 7 files changed, 17 insertions(+), 1 deletion(-) diff --git a/publish.bat b/publish.bat index 33490c42..6e32e926 100644 --- a/publish.bat +++ b/publish.bat @@ -1,2 +1,2 @@ git commit -am "publish: %1" -git push && poetry build && poetry publish && hub release create "%1" -m "Royalnet %1" \ No newline at end of file +git push && poetry build && poetry publish && hub release create "%1" -m "Royalnet %1" && sentry-cli releases deploys "%1" new --env production -n "GitHub %1" diff --git a/royalpack/commands/funkwhale.py b/royalpack/commands/funkwhale.py index 644801c0..b46cdfeb 100644 --- a/royalpack/commands/funkwhale.py +++ b/royalpack/commands/funkwhale.py @@ -23,6 +23,8 @@ class FunkwhaleCommand(PlayCommand): async with aiohttp.ClientSession() as session: async with session.get(self.config["Funkwhale"]["instance_url"] + f"/api/v1/search?query={search}") as response: + if response.status >= 400: + raise rc.ExternalError(f"Request returned {response.status}") j = await response.json() if len(j["tracks"]) < 1: raise rc.UserError("Nessun file audio trovato con il nome richiesto.") diff --git a/royalpack/commands/funkwhalealbum.py b/royalpack/commands/funkwhalealbum.py index dacfa1f0..fe132f56 100644 --- a/royalpack/commands/funkwhalealbum.py +++ b/royalpack/commands/funkwhalealbum.py @@ -23,6 +23,8 @@ class FunkwhalealbumCommand(PlayCommand): async with aiohttp.ClientSession() as session: async with session.get(self.config["Funkwhale"]["instance_url"] + f"/api/v1/search?query={search}") as response: + if response.status >= 400: + raise rc.ExternalError(f"Request returned {response.status}") j = await response.json() if len(j["albums"]) < 1: raise rc.UserError("Nessun file audio trovato con il nome richiesto.") diff --git a/royalpack/commands/funkwhaleplaylist.py b/royalpack/commands/funkwhaleplaylist.py index d1c77045..bdd3eb33 100644 --- a/royalpack/commands/funkwhaleplaylist.py +++ b/royalpack/commands/funkwhaleplaylist.py @@ -23,6 +23,8 @@ class FunkwhaleplaylistCommand(PlayCommand): async with aiohttp.ClientSession() as session: async with session.get(self.config["Funkwhale"]["instance_url"] + f"/api/v1/playlists/?q={search}&ordering=-creation_date&playable=true") as response: + if response.status >= 400: + raise rc.ExternalError(f"Request returned {response.status}") j = await response.json() if len(j["results"]) < 1: raise rc.UserError("Nessuna playlist trovata con il nome richiesto.") @@ -30,5 +32,7 @@ class FunkwhaleplaylistCommand(PlayCommand): playlist_id = playlist["id"] async with session.get(self.config["Funkwhale"]["instance_url"] + f"/api/v1/playlists/{playlist_id}/tracks") as response: + if response.status >= 400: + raise rc.ExternalError(f"Request returned {response.status}") j = await response.json() return list(map(lambda t: f'{self.config["Funkwhale"]["instance_url"]}{t["track"]["listen_url"]}', j["results"])) diff --git a/royalpack/commands/lazyfunkwhale.py b/royalpack/commands/lazyfunkwhale.py index 6edc9b09..fd3337fe 100644 --- a/royalpack/commands/lazyfunkwhale.py +++ b/royalpack/commands/lazyfunkwhale.py @@ -23,6 +23,8 @@ class LazyfunkwhaleCommand(LazyplayCommand): async with aiohttp.ClientSession() as session: async with session.get(self.config["Funkwhale"]["instance_url"] + f"/api/v1/search?query={search}") as response: + if response.status >= 400: + raise rc.ExternalError(f"Request returned {response.status}") j = await response.json() if len(j["tracks"]) < 1: raise rc.UserError("Nessun file audio trovato con il nome richiesto.") diff --git a/royalpack/commands/lazyfunkwhalealbum.py b/royalpack/commands/lazyfunkwhalealbum.py index bf807f2f..631e088e 100644 --- a/royalpack/commands/lazyfunkwhalealbum.py +++ b/royalpack/commands/lazyfunkwhalealbum.py @@ -23,6 +23,8 @@ class LazyfunkwhalealbumCommand(LazyplayCommand): async with aiohttp.ClientSession() as session: async with session.get(self.config["Funkwhale"]["instance_url"] + f"/api/v1/search?query={search}") as response: + if response.status >= 400: + raise rc.ExternalError(f"Request returned {response.status}") j = await response.json() if len(j["albums"]) < 1: raise rc.UserError("Nessun file audio trovato con il nome richiesto.") diff --git a/royalpack/commands/lazyfunkwhaleplaylist.py b/royalpack/commands/lazyfunkwhaleplaylist.py index 1fb2bcf6..caa9378d 100644 --- a/royalpack/commands/lazyfunkwhaleplaylist.py +++ b/royalpack/commands/lazyfunkwhaleplaylist.py @@ -21,6 +21,8 @@ class LazyfunkwhaleplaylistCommand(LazyplayCommand): async with aiohttp.ClientSession() as session: async with session.get(self.config["Funkwhale"]["instance_url"] + f"/api/v1/playlists/?q={search}&ordering=-creation_date&playable=true") as response: + if response.status >= 400: + raise rc.ExternalError(f"Request returned {response.status}") j = await response.json() if len(j["results"]) < 1: raise rc.UserError("Nessuna playlist trovata con il nome richiesto.") @@ -28,5 +30,7 @@ class LazyfunkwhaleplaylistCommand(LazyplayCommand): playlist_id = playlist["id"] async with session.get(self.config["Funkwhale"]["instance_url"] + f"/api/v1/playlists/{playlist_id}/tracks") as response: + if response.status >= 400: + raise rc.ExternalError(f"Request returned {response.status}") j = await response.json() return list(map(lambda t: f'{self.config["Funkwhale"]["instance_url"]}{t["track"]["listen_url"]}', j["results"]))