Piwik\Plugins\API\Renderer\Json::renderException PHP Method

renderException() public method

public renderException ( $message, Exception | Throwable $exception ) : string
$message
$exception Exception | Throwable
return string
    public function renderException($message, $exception)
    {
        $exceptionMessage = str_replace(array("\r\n", "\n"), "", $message);
        $result = json_encode(array('result' => 'error', 'message' => $exceptionMessage));
        return $this->applyJsonpIfNeeded($result);
    }

Usage Example

Example #1
0
 public function test_renderException_shouldRemoveWhitespace()
 {
     $response = $this->jsonBuilder->renderException("The\nerror\r\nmessage", new \Exception());
     $this->assertEquals('{"result":"error","message":"Theerrormessage"}', $response);
     $this->assertEquals((array) array('result' => 'error', 'message' => 'Theerrormessage'), json_decode($response, true));
     $this->assertNoJsonError($response);
 }