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):
try:
response = self.base_client.req(param, data) response = self.base_client.req(param, data)
if not response["requestStatus"]["result"]: if not response["requestStatus"]["result"]:
error = ( raise OBSSDKRequestError(
f"Request {response['requestType']} returned code {response['requestStatus']['code']}", response["requestType"],
response["requestStatus"]["code"],
response["requestStatus"].get("comment"),
) )
if "comment" in response["requestStatus"]: except OBSSDKRequestError as e:
error += (f"With message: {response['requestStatus']['comment']}",) self.logger.exception(f"{type(e).__name__}: {e}")
raise OBSSDKError("\n".join(error)) raise
if "responseData" in response: if "responseData" in response:
if raw: if raw:
return response["responseData"] return response["responseData"]