diff --git a/app/core/ErrorHandler.php b/app/core/ErrorHandler.php new file mode 100644 index 0000000..3e75063 --- /dev/null +++ b/app/core/ErrorHandler.php @@ -0,0 +1,44 @@ +errors = []; + } + + public function error($errno, $errstr, $errfile, $errline): void + { + $errstr = htmlspecialchars($errstr); + $this->errors[] = "Error[$errno]: $errstr in $errfile at line $errline"; + die(); + } + + public function exception($exception): void + { + $this->errors[] = "Uncaught Exception: " . $exception; + } + + public function __destruct() + { + if (!$this->errors) { + return; + } + ob_end_clean(); // Remove current output to be replaced by error page + http_response_code(500); + + echo ''; + echo '
Oisann! Dette var ikke ment å skje. Dersom det vedvarer, vennligst kontakt nettadministratoren.
'; + + foreach ($this->errors as $error) { + echo "