diff options
-rw-r--r-- | core/API/ApiRenderer.php | 6 | ||||
-rw-r--r-- | plugins/API/Renderer/Json.php | 8 | ||||
-rw-r--r-- | plugins/API/Renderer/Original.php | 10 |
3 files changed, 21 insertions, 3 deletions
diff --git a/core/API/ApiRenderer.php b/core/API/ApiRenderer.php index 6072bcd197..f6b616b88f 100644 --- a/core/API/ApiRenderer.php +++ b/core/API/ApiRenderer.php @@ -14,6 +14,7 @@ use Piwik\DataTable\Renderer; use Piwik\DataTable; use Piwik\Piwik; use Piwik\Plugin; +use Piwik\SettingsServer; /** * API renderer @@ -32,6 +33,11 @@ abstract class ApiRenderer { } + protected function shouldSendBacktrace() + { + return Common::isPhpCliMode() && SettingsServer::isArchivePhpTriggered(); + } + abstract public function sendHeader(); public function renderSuccess($message) diff --git a/plugins/API/Renderer/Json.php b/plugins/API/Renderer/Json.php index e33b8b7ff9..d3c3a9ab42 100644 --- a/plugins/API/Renderer/Json.php +++ b/plugins/API/Renderer/Json.php @@ -39,7 +39,13 @@ class Json extends ApiRenderer { $exceptionMessage = str_replace(array("\r\n", "\n"), " ", $message); - $result = json_encode(array('result' => 'error', 'message' => $exceptionMessage)); + $data = array('result' => 'error', 'message' => $exceptionMessage); + + if ($this->shouldSendBacktrace()) { + $data['backtrace'] = $exception->getTraceAsString(); + } + + $result = json_encode($data); return $this->applyJsonpIfNeeded($result); } diff --git a/plugins/API/Renderer/Original.php b/plugins/API/Renderer/Original.php index fa6091686c..98a8971f35 100644 --- a/plugins/API/Renderer/Original.php +++ b/plugins/API/Renderer/Original.php @@ -29,10 +29,16 @@ class Original extends ApiRenderer public function renderException($message, $exception) { if ($this->shouldSerialize()) { - return serialize([ + $data = [ 'result' => 'error', 'message' => $message, - ]); + ]; + + if ($this->shouldSendBacktrace()) { + $data['backtrace'] = $exception->getTraceAsString(); + } + + return serialize($data); } throw $exception; |