Skip to content

Commit

Permalink
Include error info if json_encode() fails.
Browse files Browse the repository at this point in the history
  • Loading branch information
eheikes committed Jan 17, 2016
1 parent 3007df0 commit 3b90c1e
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion toreadapi.php
Original file line number Diff line number Diff line change
Expand Up @@ -330,5 +330,20 @@ function deleteEntry() {
$data = $func();

header('Content-Type: application/json');
echo json_encode($data);
$encoded = json_encode($data);
if (!$encoded) {
$data['links'] = array(array(
'id' => json_last_error(),
'title' => 'API ERROR: ' . json_last_error_msg(),
'link' => 'http://php.net/manual/en/function.json-last-error.php',
'description' => null,
'time' => date('c'),
'created' => time(),
'deleted' => false,
'tags' => array()
));
$data['total'] = 1;
$encoded = json_encode($data);
}
echo $encoded;
?>

0 comments on commit 3b90c1e

Please sign in to comment.