Errors in razorCMS are handled slightly different to normal error handling, the main difference being the masking of errors from the outside world. When encountering an error in the system, we mask the error when being run as a production server to stop 3rd parties being able to gather any kind of information on the system, whilst storing this information in a log. On a production system, the only error data you will encounter will be stored in the /storage/logs directory with the default log file for the system being razor_error_log.php (a php commented file to ensure privacy from 3rd parties)
When running the system locally, razorCMS tries to capture this as best as possible, switching the system to development mode. Once in development mode, razorCMS will log all errors as before, but will also display them to the user. In the case of performing AJAX requests to a rars model, the request will also be logged to chromePHP; if you have chromePHP extension installed in chrome, and turned on, you will also see errors posted in console (F12 developer mode).
It is possible to trigger errors in your code using the trigger_error() PHP function, these errors will also be pushed through the razor error handler.
At present there is no means to extend exception handling, all exceptions are pushed through the same error handler, any exceptions thrown will be logged and will show in the log as an exception thrown. Any information thrown in with the exception will be logged against the record made.
In the case of handling exceptions from rars model files, throwing an exception will result in a response being output/returned to the requester, along with correct HTML code and headers, as well as logging the issue to the log file. Any code after an exception is thrown will not be run.
To aid debugging of AJAX requests, it is also possible to log data to the browsers console using chromePHP.
Output data to the chrome console (F12 Developer Tools). Thi srequires the installation of the chromePHP extension in your chrome browser, please search for chromePHP in the chrome store, install and activate.
// include class if not loaded (error handler should always be loaded) include_once(RAZOR_BASE_PATH.'library/php/razor/razor_error_handler.php'); // create new razor error handler object $debug = new RazorErrorHandler(); // result - if chrome PHP is turned on, your browser console should display 'Hello' $debug->chrome_php("Hello!", true);
You may also log anything you like to the error log or an optional log of your choice (in the same directory).
Write a log manually to the default razor_error_log or another log book of your choice (in the same directory).
// include class if not loaded (error handler should always be loaded) include_once(RAZOR_BASE_PATH.'library/php/razor/razor_error_handler.php'); include_once(RAZOR_BASE_PATH.'library/php/razor/razor_api.php'); // create new razor error handler object $logger = new RazorErrorHandler(); // result - the log will be written to your log file, then a response returned to requestor. $logger->log_error(["error" => "My Bad Error", "string" => "Something bad happened"], 'type-handle-extension-log'); RazorAPI::response(null, null, 500);