]> git.immae.eu Git - github/shaarli/Shaarli.git/commitdiff
Merge pull request #1601 from ArthurHoaro/feature/psr3
authorArthurHoaro <arthur@hoa.ro>
Sat, 24 Oct 2020 09:37:29 +0000 (11:37 +0200)
committerGitHub <noreply@github.com>
Sat, 24 Oct 2020 09:37:29 +0000 (11:37 +0200)
.docker/nginx.conf
application/Utils.php
application/front/controller/visitor/ErrorController.php
doc/md/Server-configuration.md
index.php

index 07fba33fec11bcbf90741c086586550a0b86c57c..023f52c1d1be5f8502c0aad2567a054b7216eb05 100644 (file)
@@ -29,7 +29,7 @@ http {
             log_not_found off;
             deny all;
         }
-        
+
         location ~ ~$ {
             # deny access to temp editor files, e.g. "script.php~"
             access_log off;
@@ -65,6 +65,11 @@ http {
             include        fastcgi.conf;
         }
 
+        location ~ /doc/ {
+            default_type "text/html";
+            try_files $uri $uri/ $uri.html =404;
+        }
+
         location ~ \.php$ {
             # deny access to all other PHP scripts
             deny all;
index 7a9d264556213e09bd173508ecf6c63c3cc41553..bc1c9f5d6133b67eacc321b3d41da57f60b0f38d 100644 (file)
@@ -465,3 +465,12 @@ function t($text, $nText = '', $nb = 1, $domain = 'shaarli')
 {
     return dn__($domain, $text, $nText, $nb);
 }
+
+/**
+ * Converts an exception into a printable stack trace string.
+ */
+function exception2text(Throwable $e): string
+{
+    return $e->getMessage() . PHP_EOL . $e->getFile() . $e->getLine() . PHP_EOL . $e->getTraceAsString();
+}
+
index 10aa84c806ea444b85a692e1d6d9d188eed4cba4..8da11172ffa52c6c8ae5967760b5a5043c05cca7 100644 (file)
@@ -28,10 +28,7 @@ class ErrorController extends ShaarliVisitorController
             // Internal error (any other Throwable)
             if ($this->container->conf->get('dev.debug', false)) {
                 $this->assignView('message', $throwable->getMessage());
-                $this->assignView(
-                    'stacktrace',
-                    nl2br(get_class($throwable) .': '. PHP_EOL . $throwable->getTraceAsString())
-                );
+                $this->assignView('stacktrace', exception2text($throwable));
             } else {
                 $this->assignView('message', t('An unexpected error occurred.'));
             }
index 8cb39934603c35aaa4b4b8ebb42fb6305052fab1..4e74d80bb28d92f4899eda3fda1610967e2bd1a5 100644 (file)
@@ -325,6 +325,11 @@ server {
         deny all;
     }
 
+    location ~ /doc/ {
+        default_type "text/html";
+        try_files $uri $uri/ $uri.html =404;
+    }
+
     location = /favicon.ico {
         # serve the Shaarli favicon from its custom location
         alias /var/www/shaarli/images/favicon.ico;
index ea6e8501f1e39f4f613765433e3ea561fdf5d69e..1b10ee41c8299f196b510bde155d6c09e8bd045b 100644 (file)
--- a/index.php
+++ b/index.php
@@ -166,6 +166,12 @@ $app->group('/api/v1', function () {
     $this->get('/history', '\Shaarli\Api\Controllers\HistoryController:getHistory')->setName('getHistory');
 })->add('\Shaarli\Api\ApiMiddleware');
 
-$response = $app->run(true);
-
-$app->respond($response);
+try {
+    $response = $app->run(true);
+    $app->respond($response);
+} catch (Throwable $e) {
+    die(nl2br(
+        'An unexpected error happened, and the error template could not be displayed.' . PHP_EOL . PHP_EOL .
+       exception2text($e)
+    ));
+}