Added checks for malformed JSON data
This commit is contained in:
parent
047c84ec3a
commit
0ebe4d5d3e
1 changed files with 6 additions and 1 deletions
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue