I have several API-s for performing some actions on my site with JSON response. Since PHP files are only accessed via AJAX, i want to change the way errors are shown.
Currently if error occurs it does something like this
die('Getting Result Error: (' . $this->sql->errno . ') ' . $this->sql->error);
So this will never get to the user (site owner) because JavaScript is handling JSON response
I'm thinking about switching to error_log
error_log('Getting Result Error: (' . $this->sql->errno . ') ' . $this->sql->error, 0);
Is this a better practice? What do you recommend.
Also I was thinking about just doing this
error_log('Getting Result Error: (' . $this->sql->errno . ') ' . $this->sql->error, 0);
header('Content-Type: application/json');
$arr = array("status"=>'error');
echo json_encode($arr, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
So i notify my script something is wrong and user will se this error, and owner of site sees it in error log.