From 5f502a5ecb69df8b579c53c9c781b8e744083fad Mon Sep 17 00:00:00 2001 From: Simon Gurcke Date: Sat, 16 Nov 2024 13:30:33 +1000 Subject: [PATCH] WIP --- apitally/client/request_logging.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/apitally/client/request_logging.py b/apitally/client/request_logging.py index abdcf12..2fe652d 100644 --- a/apitally/client/request_logging.py +++ b/apitally/client/request_logging.py @@ -169,17 +169,25 @@ def log_request(self, request: RequestDict, response: ResponseDict) -> None: response["body"] = None if request["body"] is not None and self.config.mask_request_body_callback is not None: - request["body"] = self.config.mask_request_body_callback( - request["method"], request["path"] or parsed_url.path, request["body"] - ) + try: + request["body"] = self.config.mask_request_body_callback( + request["method"], request["path"] or parsed_url.path, request["body"] + ) + except Exception: + logger.exception("User-provided mask_request_body_callback raised an exception") + request["body"] = None if request["body"] is None: request["body"] = BODY_MASKED elif len(request["body"]) > MAX_BODY_SIZE: request["body"] = BODY_TOO_LARGE if response["body"] is not None and self.config.mask_response_body_callback is not None: - response["body"] = self.config.mask_response_body_callback( - request["method"], request["path"] or parsed_url.path, response["body"] - ) + try: + response["body"] = self.config.mask_response_body_callback( + request["method"], request["path"] or parsed_url.path, response["body"] + ) + except Exception: + logger.exception("User-provided mask_response_body_callback raised an exception") + response["body"] = None if response["body"] is None: response["body"] = BODY_MASKED elif len(response["body"]) > MAX_BODY_SIZE: