OBSSDKError is now the base custom error class

OBSSDKTimeoutError and OBSSDKRequestError subclass it

req_name and error code set as error class attributes.
This commit is contained in:
onyx-and-iris 2023-08-11 22:32:50 +01:00
parent 5db7a705c5
commit f3e75c0ddf

View File

@ -1,6 +1,21 @@
class OBSSDKError(Exception): class OBSSDKError(Exception):
"""Exception raised when general errors occur""" """Base class for OBSSDK errors"""
class OBSSDKTimeoutError(Exception): class OBSSDKTimeoutError(OBSSDKError):
"""Exception raised when a connection times out""" """Exception raised when a connection times out"""
class OBSSDKRequestError(OBSSDKError):
"""Exception raised when a request returns an error code"""
def __init__(self, req_name, code, message=None):
self.req_name = req_name
self.code = code
self.message = " ".join(
[
f"Request {self.req_name} returned code {self.code}.",
f"With message: {message}" if message else "",
]
)
super().__init__(self.message)