diff options
author | Matthieu Aubry <mattab@users.noreply.github.com> | 2016-08-23 05:09:25 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-08-23 05:09:25 +0300 |
commit | 5dd7d84e2106065c63bd057d8be3c31f74bf9aed (patch) | |
tree | 83452bc3686a6ad4a59a350af1b9d9281997fa46 | |
parent | 26e10c299cfa78d1ed3f8c5dc4522b87b25e25b3 (diff) |
PHP 7: when there is a fatal error in API request processing, display the original error in the api response (#10406)
* PHP 7: when there is a fatal error in API request processing, display the original error
* PHP 7 compatibility
-rw-r--r-- | core/API/ApiRenderer.php | 7 | ||||
-rw-r--r-- | core/API/ResponseBuilder.php | 10 | ||||
-rw-r--r-- | core/Tracker/Response.php | 2 | ||||
-rw-r--r-- | plugins/API/Renderer/Console.php | 7 | ||||
-rw-r--r-- | plugins/API/Renderer/Csv.php | 7 | ||||
-rw-r--r-- | plugins/API/Renderer/Html.php | 7 | ||||
-rw-r--r-- | plugins/API/Renderer/Json.php | 7 | ||||
-rw-r--r-- | plugins/API/Renderer/Original.php | 8 | ||||
-rw-r--r-- | plugins/API/Renderer/Php.php | 7 | ||||
-rw-r--r-- | plugins/API/Renderer/Rss.php | 7 | ||||
-rw-r--r-- | plugins/API/Renderer/Xml.php | 7 | ||||
-rw-r--r-- | plugins/BulkTracking/tests/Framework/Mock/Tracker/Response.php | 2 | ||||
-rw-r--r-- | plugins/BulkTracking/tests/Unit/ResponseTest.php | 2 | ||||
-rw-r--r-- | tests/PHPUnit/Unit/Tracker/ResponseTest.php | 2 |
14 files changed, 66 insertions, 16 deletions
diff --git a/core/API/ApiRenderer.php b/core/API/ApiRenderer.php index 36f84e63c2..fc1c11d736 100644 --- a/core/API/ApiRenderer.php +++ b/core/API/ApiRenderer.php @@ -39,7 +39,12 @@ abstract class ApiRenderer return 'Success:' . $message; } - public function renderException($message, \Exception $exception) + /** + * @param $message + * @param Exception|\Throwable $exception + * @return mixed + */ + public function renderException($message, $exception) { return $message; } diff --git a/core/API/ResponseBuilder.php b/core/API/ResponseBuilder.php index d6b6cb9664..bc90598f89 100644 --- a/core/API/ResponseBuilder.php +++ b/core/API/ResponseBuilder.php @@ -138,10 +138,10 @@ class ResponseBuilder } /** - * @param Exception $e + * @param Exception|\Throwable $e * @return Exception */ - private function decorateExceptionWithDebugTrace(Exception $e) + private function decorateExceptionWithDebugTrace($e) { // If we are in tests, show full backtrace if (defined('PIWIK_PATH_TEST_TO_ROOT')) { @@ -157,7 +157,11 @@ class ResponseBuilder return $e; } - private function formatExceptionMessage(Exception $exception) + /** + * @param Exception|\Throwable $exception + * @return string + */ + private function formatExceptionMessage($exception) { $message = $exception->getMessage(); if (\Piwik_ShouldPrintBackTraceWithMessage()) { diff --git a/core/Tracker/Response.php b/core/Tracker/Response.php index 2b4a6f3b49..bf8c6f9955 100644 --- a/core/Tracker/Response.php +++ b/core/Tracker/Response.php @@ -175,7 +175,7 @@ class Response return $e->getMessage(); } - protected function logExceptionToErrorLog(Exception $e) + protected function logExceptionToErrorLog($e) { error_log(sprintf("Error in Piwik (tracker): %s", str_replace("\n", " ", $this->getMessageFromException($e)))); } diff --git a/plugins/API/Renderer/Console.php b/plugins/API/Renderer/Console.php index 40794ef8e9..98e3d01d1f 100644 --- a/plugins/API/Renderer/Console.php +++ b/plugins/API/Renderer/Console.php @@ -16,7 +16,12 @@ use Piwik\DataTable; class Console extends ApiRenderer { - public function renderException($message, \Exception $exception) + /** + * @param $message + * @param Exception|\Throwable $exception + * @return string + */ + public function renderException($message, $exception) { self::sendHeader(); diff --git a/plugins/API/Renderer/Csv.php b/plugins/API/Renderer/Csv.php index 468a3a2588..77caa50bce 100644 --- a/plugins/API/Renderer/Csv.php +++ b/plugins/API/Renderer/Csv.php @@ -23,7 +23,12 @@ class Csv extends ApiRenderer return "message\n" . $message; } - public function renderException($message, \Exception $exception) + /** + * @param $message + * @param Exception|\Throwable $exception + * @return string + */ + public function renderException($message, $exception) { Common::sendHeader('Content-Type: text/html; charset=utf-8', true); return 'Error: ' . $message; diff --git a/plugins/API/Renderer/Html.php b/plugins/API/Renderer/Html.php index 4037c35b4e..48acbb355f 100644 --- a/plugins/API/Renderer/Html.php +++ b/plugins/API/Renderer/Html.php @@ -16,7 +16,12 @@ use Piwik\DataTable; class Html extends ApiRenderer { - public function renderException($message, \Exception $exception) + /** + * @param $message + * @param Exception|\Throwable $exception + * @return string + */ + public function renderException($message, $exception) { Common::sendHeader('Content-Type: text/plain; charset=utf-8', true); diff --git a/plugins/API/Renderer/Json.php b/plugins/API/Renderer/Json.php index 1dffa1f45f..5037b30fbe 100644 --- a/plugins/API/Renderer/Json.php +++ b/plugins/API/Renderer/Json.php @@ -31,7 +31,12 @@ class Json extends ApiRenderer return $this->applyJsonpIfNeeded($result); } - public function renderException($message, \Exception $exception) + /** + * @param $message + * @param Exception|\Throwable $exception + * @return string + */ + public function renderException($message, $exception) { $exceptionMessage = str_replace(array("\r\n", "\n"), "", $message); diff --git a/plugins/API/Renderer/Original.php b/plugins/API/Renderer/Original.php index a0730acf2b..96895b8012 100644 --- a/plugins/API/Renderer/Original.php +++ b/plugins/API/Renderer/Original.php @@ -18,7 +18,13 @@ class Original extends ApiRenderer return true; } - public function renderException($message, \Exception $exception) + /** + * @param $message + * @param \Exception|\Throwable $exception + * @throws \Exception|\Throwable + * @return void + */ + public function renderException($message, $exception) { throw $exception; } diff --git a/plugins/API/Renderer/Php.php b/plugins/API/Renderer/Php.php index 81a512122d..5823137569 100644 --- a/plugins/API/Renderer/Php.php +++ b/plugins/API/Renderer/Php.php @@ -23,7 +23,12 @@ class Php extends ApiRenderer return $this->serializeIfNeeded($success); } - public function renderException($message, \Exception $exception) + /** + * @param $message + * @param Exception|\Throwable $exception + * @return string + */ + public function renderException($message, $exception) { $message = array('result' => 'error', 'message' => $message); diff --git a/plugins/API/Renderer/Rss.php b/plugins/API/Renderer/Rss.php index 3ee1c287bc..5bbcac78aa 100644 --- a/plugins/API/Renderer/Rss.php +++ b/plugins/API/Renderer/Rss.php @@ -16,7 +16,12 @@ use Piwik\DataTable; class Rss extends ApiRenderer { - public function renderException($message, \Exception $exception) + /** + * @param $message + * @param \Exception|\Throwable $exception + * @return string + */ + public function renderException($message, $exception) { self::sendHeader('plain'); diff --git a/plugins/API/Renderer/Xml.php b/plugins/API/Renderer/Xml.php index 99092ee057..4a1f0247d7 100644 --- a/plugins/API/Renderer/Xml.php +++ b/plugins/API/Renderer/Xml.php @@ -24,7 +24,12 @@ class Xml extends ApiRenderer "</result>"; } - public function renderException($message, \Exception $exception) + /** + * @param $message + * @param \Exception|\Throwable $exception + * @return string + */ + public function renderException($message, $exception) { return '<?xml version="1.0" encoding="utf-8" ?>' . "\n" . "<result>\n" . diff --git a/plugins/BulkTracking/tests/Framework/Mock/Tracker/Response.php b/plugins/BulkTracking/tests/Framework/Mock/Tracker/Response.php index e514745ddb..c595a278c6 100644 --- a/plugins/BulkTracking/tests/Framework/Mock/Tracker/Response.php +++ b/plugins/BulkTracking/tests/Framework/Mock/Tracker/Response.php @@ -13,7 +13,7 @@ use Exception; class Response extends \Piwik\Plugins\BulkTracking\Tracker\Response { - protected function logExceptionToErrorLog(Exception $e) + protected function logExceptionToErrorLog($e) { // prevent from writing to console in tests } diff --git a/plugins/BulkTracking/tests/Unit/ResponseTest.php b/plugins/BulkTracking/tests/Unit/ResponseTest.php index 38c3c0cce1..91dbfc2079 100644 --- a/plugins/BulkTracking/tests/Unit/ResponseTest.php +++ b/plugins/BulkTracking/tests/Unit/ResponseTest.php @@ -15,7 +15,7 @@ use Exception; class TestResponse extends Response { - protected function logExceptionToErrorLog(Exception $e) + protected function logExceptionToErrorLog($e) { // prevent console from outputting the error_log message } diff --git a/tests/PHPUnit/Unit/Tracker/ResponseTest.php b/tests/PHPUnit/Unit/Tracker/ResponseTest.php index 93d8a70ad4..4d902ada08 100644 --- a/tests/PHPUnit/Unit/Tracker/ResponseTest.php +++ b/tests/PHPUnit/Unit/Tracker/ResponseTest.php @@ -16,7 +16,7 @@ use Exception; class TestResponse extends Response { - protected function logExceptionToErrorLog(Exception $e) + protected function logExceptionToErrorLog($e) { // prevent console from outputting the error_log message } |