From f3e75c0ddfe9ea600daedee5c2b7b71e038814d6 Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Fri, 11 Aug 2023 22:32:50 +0100 Subject: [PATCH] OBSSDKError is now the base custom error class OBSSDKTimeoutError and OBSSDKRequestError subclass it req_name and error code set as error class attributes. --- obsws_python/error.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/obsws_python/error.py b/obsws_python/error.py index 42719b1..ae310f7 100644 --- a/obsws_python/error.py +++ b/obsws_python/error.py @@ -1,6 +1,21 @@ 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""" + + +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)