send now raises an OBSSDKRequestError

it is then logged and rethrown
This commit is contained in:
onyx-and-iris 2023-08-11 22:33:41 +01:00
parent f3e75c0ddf
commit ffd215aadf

View File

@ -1,7 +1,7 @@
import logging import logging
from .baseclient import ObsClient from .baseclient import ObsClient
from .error import OBSSDKError from .error import OBSSDKError, OBSSDKRequestError
from .util import as_dataclass from .util import as_dataclass
""" """
@ -43,14 +43,17 @@ class ReqClient:
return type(self).__name__ return type(self).__name__
def send(self, param, data=None, raw=False): def send(self, param, data=None, raw=False):
response = self.base_client.req(param, data) try:
if not response["requestStatus"]["result"]: response = self.base_client.req(param, data)
error = ( if not response["requestStatus"]["result"]:
f"Request {response['requestType']} returned code {response['requestStatus']['code']}", raise OBSSDKRequestError(
) response["requestType"],
if "comment" in response["requestStatus"]: response["requestStatus"]["code"],
error += (f"With message: {response['requestStatus']['comment']}",) response["requestStatus"].get("comment"),
raise OBSSDKError("\n".join(error)) )
except OBSSDKRequestError as e:
self.logger.exception(f"{type(e).__name__}: {e}")
raise
if "responseData" in response: if "responseData" in response:
if raw: if raw:
return response["responseData"] return response["responseData"]