3 declare(strict_types
=1);
5 namespace Shaarli\Front\Controller\Visitor
;
7 use Shaarli\Front\Exception\ShaarliFrontException
;
9 use Slim\Http\Response
;
12 * Controller used to render the error page, with a provided exception.
13 * It is actually used as a Slim error handler.
15 class ErrorController
extends ShaarliVisitorController
17 public function __invoke(Request
$request, Response
$response, \Throwable
$throwable): Response
19 // Unknown error encountered
20 $this->container
->pageBuilder
->reset();
22 if ($throwable instanceof ShaarliFrontException
) {
24 $this->assignView('message', nl2br($throwable->getMessage()));
26 $response = $response->withStatus($throwable->getCode());
28 // Internal error (any other Throwable)
29 if ($this->container
->conf
->get('dev.debug', false)) {
30 $this->assignView('message', $throwable->getMessage());
33 nl2br(get_class($throwable) .': '. PHP_EOL
. $throwable->getTraceAsString())
36 $this->assignView('message', t('An unexpected error occurred.'));
39 $response = $response->withStatus(500);
43 return $response->write($this->render('error'));