aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--application/Utils.php9
-rw-r--r--application/front/controller/visitor/ErrorController.php5
-rw-r--r--index.php12
3 files changed, 19 insertions, 7 deletions
diff --git a/application/Utils.php b/application/Utils.php
index bcfda65c..37be9a13 100644
--- a/application/Utils.php
+++ b/application/Utils.php
@@ -463,3 +463,12 @@ function t($text, $nText = '', $nb = 1, $domain = 'shaarli')
463{ 463{
464 return dn__($domain, $text, $nText, $nb); 464 return dn__($domain, $text, $nText, $nb);
465} 465}
466
467/**
468 * Converts an exception into a printable stack trace string.
469 */
470function exception2text(Throwable $e): string
471{
472 return $e->getMessage() . PHP_EOL . $e->getFile() . $e->getLine() . PHP_EOL . $e->getTraceAsString();
473}
474
diff --git a/application/front/controller/visitor/ErrorController.php b/application/front/controller/visitor/ErrorController.php
index 10aa84c8..8da11172 100644
--- a/application/front/controller/visitor/ErrorController.php
+++ b/application/front/controller/visitor/ErrorController.php
@@ -28,10 +28,7 @@ class ErrorController extends ShaarliVisitorController
28 // Internal error (any other Throwable) 28 // Internal error (any other Throwable)
29 if ($this->container->conf->get('dev.debug', false)) { 29 if ($this->container->conf->get('dev.debug', false)) {
30 $this->assignView('message', $throwable->getMessage()); 30 $this->assignView('message', $throwable->getMessage());
31 $this->assignView( 31 $this->assignView('stacktrace', exception2text($throwable));
32 'stacktrace',
33 nl2br(get_class($throwable) .': '. PHP_EOL . $throwable->getTraceAsString())
34 );
35 } else { 32 } else {
36 $this->assignView('message', t('An unexpected error occurred.')); 33 $this->assignView('message', t('An unexpected error occurred.'));
37 } 34 }
diff --git a/index.php b/index.php
index 220847f5..b6ee8ebc 100644
--- a/index.php
+++ b/index.php
@@ -151,6 +151,12 @@ $app->group('/api/v1', function () {
151 $this->get('/history', '\Shaarli\Api\Controllers\HistoryController:getHistory')->setName('getHistory'); 151 $this->get('/history', '\Shaarli\Api\Controllers\HistoryController:getHistory')->setName('getHistory');
152})->add('\Shaarli\Api\ApiMiddleware'); 152})->add('\Shaarli\Api\ApiMiddleware');
153 153
154$response = $app->run(true); 154try {
155 155 $response = $app->run(true);
156$app->respond($response); 156 $app->respond($response);
157} catch (Throwable $e) {
158 die(nl2br(
159 'An unexpected error happened, and the error template could not be displayed.' . PHP_EOL . PHP_EOL .
160 exception2text($e)
161 ));
162}