Merge pull request #1602 from ArthurHoaro/fix/root-exceptions
Dislay an error if an exception occurs in the error handler
This commit is contained in:
commit
3445443349
3 changed files with 19 additions and 7 deletions
|
@ -463,3 +463,12 @@ function t($text, $nText = '', $nb = 1, $domain = 'shaarli')
|
||||||
{
|
{
|
||||||
return dn__($domain, $text, $nText, $nb);
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,10 +28,7 @@ public function __invoke(Request $request, Response $response, \Throwable $throw
|
||||||
// Internal error (any other Throwable)
|
// Internal error (any other Throwable)
|
||||||
if ($this->container->conf->get('dev.debug', false)) {
|
if ($this->container->conf->get('dev.debug', false)) {
|
||||||
$this->assignView('message', $throwable->getMessage());
|
$this->assignView('message', $throwable->getMessage());
|
||||||
$this->assignView(
|
$this->assignView('stacktrace', exception2text($throwable));
|
||||||
'stacktrace',
|
|
||||||
nl2br(get_class($throwable) .': '. PHP_EOL . $throwable->getTraceAsString())
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
$this->assignView('message', t('An unexpected error occurred.'));
|
$this->assignView('message', t('An unexpected error occurred.'));
|
||||||
}
|
}
|
||||||
|
|
|
@ -151,6 +151,12 @@
|
||||||
$this->get('/history', '\Shaarli\Api\Controllers\HistoryController:getHistory')->setName('getHistory');
|
$this->get('/history', '\Shaarli\Api\Controllers\HistoryController:getHistory')->setName('getHistory');
|
||||||
})->add('\Shaarli\Api\ApiMiddleware');
|
})->add('\Shaarli\Api\ApiMiddleware');
|
||||||
|
|
||||||
|
try {
|
||||||
$response = $app->run(true);
|
$response = $app->run(true);
|
||||||
|
|
||||||
$app->respond($response);
|
$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)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue