diff --git a/src/library/Box/Exception.php b/src/library/Box/Exception.php index ce681fa10..80b046b8f 100644 --- a/src/library/Box/Exception.php +++ b/src/library/Box/Exception.php @@ -1,4 +1,5 @@ stackTrace($stackLength) ); + error_log($this->stackTrace($stackLength, $protected)); } // Translate the exception @@ -39,12 +42,14 @@ class Box_Exception extends Exception parent::__construct($message, $code); } + /** * Big thank you to jhurliman and jambroseclarke on Stack Overflow for this backtrace formatter. * We have slightly modified it for our purposes * https://stackoverflow.com/a/32365961 */ - private function stackTrace($Length = 25) { + private function stackTrace($Length = 25, $protected = false) + { $stack = debug_backtrace($Length); $output = ''; @@ -53,11 +58,13 @@ class Box_Exception extends Exception $entry = $stack[$i]; $func = $entry['function'] . '('; - if(isset($entry['args'])){ + if (isset($entry['args'])) { $argsLen = count($entry['args']); for ($j = 0; $j < $argsLen; $j++) { $my_entry = $entry['args'][$j]; - if (is_string($my_entry)) { + if ($protected) { + $func .= "***"; + } else if (is_string($my_entry)) { $func .= $my_entry; } if ($j < $argsLen - 1) $func .= ', '; @@ -67,7 +74,7 @@ class Box_Exception extends Exception $entry_file = 'NO_FILE'; if (array_key_exists('file', $entry)) { - $entry_file = str_replace(PATH_ROOT, '' , $entry['file']); + $entry_file = str_replace(PATH_ROOT, '', $entry['file']); } $entry_line = 'NO_LINE'; if (array_key_exists('line', $entry)) { diff --git a/src/library/Payment/Exception.php b/src/library/Payment/Exception.php index cd8b094ec..e20567836 100644 --- a/src/library/Payment/Exception.php +++ b/src/library/Payment/Exception.php @@ -12,20 +12,18 @@ * with this source code in the file LICENSE */ -class Payment_Exception extends Exception +class Payment_Exception extends Box_Exception { - /** - * Creates a new translated exception. - * - * @param string error message - * @param array translation variables - */ - public function __construct($message, array $variables = NULL, $code = 0) + /** + * Creates a new translated exception, using the Box_Exception class. + * + * @param string error message + * @param array|null translation variables + * @param int The exception code. + * @param bool If the varibles in this should be considered protect, if so, disable stacktracing abilities. + */ + public function __construct(string $message, array $variables = NULL, int $code = 0) { - // Set the message - $message = __trans($message, $variables); - - // Pass the message to the parent - parent::__construct($message, $code); + parent:: __construct($message, $variables, $code, true); } } diff --git a/src/library/Registrar/Exception.php b/src/library/Registrar/Exception.php index 806ede2e9..1499c1c69 100644 --- a/src/library/Registrar/Exception.php +++ b/src/library/Registrar/Exception.php @@ -1,5 +1,16 @@