From 2a4ce65a20b41a670b274cb473d46e62b4f3c913 Mon Sep 17 00:00:00 2001 From: Alejandro Sirgo Rica Date: Mon, 18 Mar 2024 14:17:12 +0100 Subject: src: centralize error logging into send_internal_server_error Use only the exception messages as the main resource for error messages. The previous error code had string duplication in the form of: logging.error('msg here') raise Exception('msg here') That approach also has the downside of having log duplication as it had the local logging.err() and a global logging.exception() inside send_internal_server_error capturing the exception message. The actual code only requires raising an exception with a proper error message. Improve exception messages to give more error context. Log every AssertionError as a backtrace. Use the 'raise Exception from e' syntax to modify the a previously raised exception 'e' into an exception with aditional context or different type. This also prevents the message that warns about newer exceptions being launch after an initial exception. --- src/ogRest.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/ogRest.py') diff --git a/src/ogRest.py b/src/ogRest.py index 7848c3d..47767b6 100644 --- a/src/ogRest.py +++ b/src/ogRest.py @@ -266,8 +266,10 @@ class ogRest(): raise ValueError('Mode not supported.') def send_internal_server_error(self, client, exc=None): - if exc: - logging.exception('Unexpected error') + if isinstance(exc, AssertionError): + logging.exception(exc) + else: + logging.error(exc) response = restResponse(ogResponses.INTERNAL_ERR, seq=client.seq) client.send(response.get()) self.state = ThreadState.IDLE -- cgit v1.2.3-18-g5258