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