Skip to content

Commit efc28ee

Browse files
Kamal Sai DevarapalliKamal Sai Devarapalli
authored andcommitted
Fix exception handling and logging in base error handler
- Add pylint disable comments for intentional broad exception catching - Update logging to use lazy % formatting for better performance - Improve error logging format consistency
1 parent c98ce73 commit efc28ee

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

common/pyportal_common/error_handlers/base_error_handler.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,12 @@ def prepare_error_response(self) -> Union[dict, None]:
3232
self.cmn_logger.info(
3333
f"Prepared Err_response :: [SUCCESS] : {error_res}")
3434
return error_res
35+
# pylint: disable=broad-except
3536
except Exception as ex:
3637
self.cmn_logger.error(
37-
f"Error occurred :: {ex}\tLine No:: {sys.exc_info()[2].tb_lineno}")
38+
"Error occurred :: %s\tLine No:: %s",
39+
ex, sys.exc_info()[2].tb_lineno
40+
)
3841

3942
def serialize_prepared_error_response(
4043
self, prep_error_res: dict) -> Union[make_response, None]:
@@ -54,9 +57,12 @@ def serialize_prepared_error_response(
5457
self.cmn_logger.debug(
5558
f"Prepared Err_response :: [SUCCESS]:: {err_response}")
5659
return err_response
60+
# pylint: disable=broad-except
5761
except Exception as ex:
5862
self.cmn_logger.error(
59-
f"Error occurred :: {ex}\tLine No:: {sys.exc_info()[2].tb_lineno}")
63+
"Error occurred :: %s\tLine No:: %s",
64+
ex, sys.exc_info()[2].tb_lineno
65+
)
6066

6167
@property
6268
def send_response_to_client(self) -> Union[make_response, None]:

0 commit comments

Comments
 (0)