2 # custom error handling for MinimEdit
4 function abort($body, string $status = NULL)
7 header("HTTP/1.1 $status");
8 if ($status[0] === '3') {
9 # redirection (body specifies target)
10 header("Location: $body");
14 header('Content-Type: text/plain; charset=utf-8');
22 http_response_code(500);
24 require_once('article.inc.php');
25 $Page = new ArchiveArticle(NULL);
26 $Page->title = 'Fout';
28 include_once 'page.inc.php';
31 require '500.inc.html';
32 $Page->place['debug'] = htmlspecialchars($error);
33 $Page->raw = ob_get_clean();
34 print $Page->render();
37 set_exception_handler('fail');
39 define('E_FATAL', E_ERROR | E_CORE_ERROR | E_COMPILE_ERROR | E_USER_ERROR);
41 set_error_handler(function ($level, $error, $file, $line) {
42 if ($level & E_FATAL) {
49 register_shutdown_function(function () {
50 # display failure page for fatal exceptions
51 $error = error_get_last();
52 if (!($error['type'] & E_FATAL)) return;
53 fail("Fatal: $error[message] in $error[file]:$error[line]");
56 error_reporting(error_reporting() & ~E_FATAL);