Some temporary error handling
This commit is contained in:
parent
dc07f5e757
commit
fc38673b7d
@ -1,11 +1,13 @@
|
||||
<?php
|
||||
|
||||
function print_error($title, $message) {
|
||||
require_once(__DIR__ . '/output.php');
|
||||
|
||||
$error = array();
|
||||
$error['type'] = 'ERROR';
|
||||
$error['title'] = $title;
|
||||
$error['message'] = $message;
|
||||
|
||||
print json_encode($error);
|
||||
print output($error);
|
||||
return;
|
||||
}
|
@ -10,13 +10,31 @@ require(__DIR__ . '/../hesk_settings.inc.php');
|
||||
require(__DIR__ . '/controllers/CategoryController.php');
|
||||
hesk_load_api_database_functions();
|
||||
|
||||
// Properly handle error logging, as well as a fatal error workaround
|
||||
error_reporting(0); // Override hesk_settings. We're smarter than it
|
||||
set_error_handler('errorHandler');
|
||||
register_shutdown_function('fatalErrorShutdownHandler');
|
||||
|
||||
function handle404() {
|
||||
http_response_code(404);
|
||||
print json_encode('404 found');
|
||||
}
|
||||
|
||||
function assertApiIsEnabled() {
|
||||
//-- TODO
|
||||
throw new Exception("Some exception here!", 33);
|
||||
}
|
||||
|
||||
function errorHandler($errorNumber, $errorMessage, $errorFile, $errorLine) {
|
||||
print_error(sprintf("Uncaught error in %s", $errorFile), $errorMessage);
|
||||
die();
|
||||
}
|
||||
|
||||
function fatalErrorShutdownHandler() {
|
||||
$last_error = error_get_last();
|
||||
if ($last_error['type'] === E_ERROR) {
|
||||
// fatal error
|
||||
errorHandler(E_ERROR, $last_error['message'], $last_error['file'], $last_error['line']);
|
||||
}
|
||||
}
|
||||
|
||||
// Must use fully-qualified namespace to controllers
|
||||
|
Loading…
x
Reference in New Issue
Block a user