From a7ef61018b94f73224b2fbdfe46a00bbcdf09a25 Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Mon, 14 Aug 2023 00:44:59 +0100 Subject: [PATCH] refactor OBSSDKRequestError reword error section in README --- README.md | 14 +++++++------- obsws_python/error.py | 13 +++++-------- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 4526967..ab55d12 100644 --- a/README.md +++ b/README.md @@ -128,13 +128,13 @@ def on_scene_created(data): ### Errors -A base error class `OBSSDKError` may be used to catch OBSSDK error types. - -If a request returns an error code an `OBSSDKRequestError` will be raised. - -For a full list of status codes refer to [Codes](https://github.com/obsproject/obs-websocket/blob/master/docs/generated/protocol.md#requeststatus) - -If a timeout occurs during sending/receiving a request or receiving an event an `OBSSDKTimeoutError` will be raised. +- `OBSSDKError`: Base error class. +- `OBSSDKTimeoutError`: Raised if a timeout occurs during sending/receiving a request or receiving an event +- `OBSSDKRequestError`: Raised when a request returns an error code. + - The following attributes are available: + - `req_name`: name of the request. + - `code`: request status code. + - For a full list of status codes refer to [Codes](https://github.com/obsproject/obs-websocket/blob/master/docs/generated/protocol.md#requeststatus) ### Logging diff --git a/obsws_python/error.py b/obsws_python/error.py index ae310f7..f1a2f6c 100644 --- a/obsws_python/error.py +++ b/obsws_python/error.py @@ -9,13 +9,10 @@ class OBSSDKTimeoutError(OBSSDKError): class OBSSDKRequestError(OBSSDKError): """Exception raised when a request returns an error code""" - def __init__(self, req_name, code, message=None): + def __init__(self, req_name, code, comment): 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) + message = f"Request {self.req_name} returned code {self.code}." + if comment: + message += f" With message: {comment}" + super().__init__(message)