Fix borked API, makes webstudio not white screen.

This commit is contained in:
Matthew Stratford 2021-09-25 19:25:23 +01:00
parent 212f449e13
commit 2b2e77fb27

View file

@ -102,16 +102,21 @@ class MyRadioAPI:
self._log("Requesting API V2 URL with method {}: {}".format(method, url))
request = None
if method == "GET":
request = await self.async_call(url, method="GET", timeout=timeout)
elif method == "POST":
self._log("POST data: {}".format(data))
request = await self.async_call(url, data=data, method="POST", timeout=timeout)
elif method == "PUT":
request = await self.async_call(url, method="PUT", timeout=timeout)
else:
self._logException("Invalid API method. Request not sent.")
try:
if method == "GET":
request = await self.async_call(url, method="GET", timeout=timeout)
elif method == "POST":
self._log("POST data: {}".format(data))
request = await self.async_call(url, data=data, method="POST", timeout=timeout)
elif method == "PUT":
request = await self.async_call(url, method="PUT", timeout=timeout)
else:
self._logException("Invalid API method. Request not sent.")
return None
except aiohttp.ClientError:
self._logException("Failed async API request.")
return None
self._log("Finished request.")
return request
@ -291,7 +296,7 @@ class MyRadioAPI:
if not request or not isinstance(request, bytes):
self._logException("Failed to retrieve music playlists.")
return None
return []
return json.loads(request)["payload"]
@ -302,7 +307,7 @@ class MyRadioAPI:
if not request or not isinstance(request, bytes):
self._logException("Failed to retrieve music playlists.")
return None
return []
return json.loads(request)["payload"]
@ -319,7 +324,7 @@ class MyRadioAPI:
self._logException(
"Failed to retrieve items for aux playlist {}.".format(library_id)
)
return None
return []
return json.loads(request)["payload"]
@ -333,7 +338,7 @@ class MyRadioAPI:
self._logException(
"Failed to retrieve items for music playlist {}.".format(library_id)
)
return None
return []
return json.loads(request)["payload"]
@ -347,7 +352,7 @@ class MyRadioAPI:
if not request or not isinstance(request, bytes):
self._logException("Failed to search for track.")
return None
return []
return json.loads(request)["payload"]