Added checks for malformed JSON data

This commit is contained in:
Marcin Kurczewski 2014-09-16 14:42:25 +02:00
parent 047c84ec3a
commit 0ebe4d5d3e

View file

@ -20,7 +20,12 @@ class HttpHelper
public function outputJSON($data)
{
$this->output(json_encode((array) $data));
$encodedJson = json_encode((array) $data);
$lastError = json_last_error();
if ($lastError !== JSON_ERROR_NONE)
$this->output('Fatal error while encoding JSON: ' . $lastError . PHP_EOL . PHP_EOL . print_r($data, true));
else
$this->output($encodedJson);
}
public function getRequestHeaders()