From 31ca68872076706bb3f66aad786c2f07e1f730f0 Mon Sep 17 00:00:00 2001 From: Gopi Date: Fri, 14 Jun 2024 18:26:18 +0100 Subject: [PATCH 1/2] Log the request and response inside CRM_Mailchimp_Exception --- CRM/Mailchimp/Exception.php | 4 ++++ CRM/Mailchimp/Utils.php | 14 ++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/CRM/Mailchimp/Exception.php b/CRM/Mailchimp/Exception.php index 71989aa..8a2e1fe 100644 --- a/CRM/Mailchimp/Exception.php +++ b/CRM/Mailchimp/Exception.php @@ -14,6 +14,10 @@ public function __construct(CRM_Mailchimp_Api3 $api, $message_prefix='') { $this->request = isset($api->request) ? clone($api->request) : NULL; $this->response = isset($api->response) ? clone($api->response) : NULL; + // log the request & response in the error logs + CRM_Mailchimp_Utils::logErrors('Mailchimp Request', $this->request); + CRM_Mailchimp_Utils::logErrors('Mailchimp Response', $this->response); + if (isset($this->response->data->title)) { $message = $message_prefix . 'Mailchimp API said: ' . $this->response->data->title . (empty($this->response->data->detail) ? '' : " (" . $this->response->data->detail . ")"); diff --git a/CRM/Mailchimp/Utils.php b/CRM/Mailchimp/Utils.php index 9f9dfb0..f470d9a 100644 --- a/CRM/Mailchimp/Utils.php +++ b/CRM/Mailchimp/Utils.php @@ -639,6 +639,20 @@ public static function checkDebug($description, $variable='VARIABLE_NOT_PROVIDED } } + /** + * Log the error message in mailchimp log file + */ + /* + * Function to log Errors in ConfigLog + * + * @param string $description - description to print in log + * @param array $variable - variable to print in log + * + */ + public static function logErrors($description = 'No description', $variable = array()) { + CRM_Core_Error::debug_var("Error : " . $description, ts($variable), TRUE, TRUE, 'mailchimp'); + } + /** * Access our cached data. */ From 0315425881b914f07d721cb4f153c777c2ad3759 Mon Sep 17 00:00:00 2001 From: Gopi Date: Fri, 14 Jun 2024 18:35:04 +0100 Subject: [PATCH 2/2] Fix on logError to handle all type of variables --- CRM/Mailchimp/Utils.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CRM/Mailchimp/Utils.php b/CRM/Mailchimp/Utils.php index f470d9a..4c99a30 100644 --- a/CRM/Mailchimp/Utils.php +++ b/CRM/Mailchimp/Utils.php @@ -650,7 +650,7 @@ public static function checkDebug($description, $variable='VARIABLE_NOT_PROVIDED * */ public static function logErrors($description = 'No description', $variable = array()) { - CRM_Core_Error::debug_var("Error : " . $description, ts($variable), TRUE, TRUE, 'mailchimp'); + CRM_Core_Error::debug_var("Error : " . $description, $variable, TRUE, TRUE, 'mailchimp'); } /**