nicer exception handling
[pharext/pharext.org] / public / index.php
index 8d0bf63970aeb79d4f3effa70f76893badc0e84e..7603f62973f67b31d91940ea33255e80e98b8129 100644 (file)
@@ -2,6 +2,38 @@
 
 namespace app;
 
-$bootstrap = require "../app/bootstrap.php";
-$injector = $bootstrap(["config", "github", "plates", "web"]);
-$injector->execute(Web::class);
+try {
+       $bootstrap = require "../app/bootstrap.php";
+       $injector = $bootstrap(["config", "github", "plates", "model", "web"]);
+       return $injector->execute(Web::class);
+} catch (\Exception $e) {
+       $error = $e->getMessage();
+       $stack = $e->getTraceAsString();
+       @header("X-Exception: ".get_class($e), false, 500);
+       Web::cleanBuffers();
+}
+?>
+<html>
+       <head>
+               <meta charset="utf-8">
+               <title>Application Error</title>
+               <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
+       </head>
+       <body>
+               <div class="container">
+                       <div class="jumbotron">
+                               <h1>Application Error</h1>
+                               <h2>Aww, you really gotta do that?!</h2>
+                               <p class="text-danger">
+                                       <strong><?= htmlspecialchars($error) ?></strong>
+                               </p>
+                               <p>
+                                       Sorry, anyway.
+                               </p>
+                       </div>
+                       <?php if (APP_ENVIRONMENT != "production") : ?>
+                       <pre><?= htmlspecialchars($stack) ?></pre>
+                       <?php endif; ?>
+               </div>
+       </body>
+</html>