]> git.immae.eu Git - github/shaarli/Shaarli.git/blame - application/front/controller/visitor/ErrorController.php
Display error details even with dev.debug set to false
[github/shaarli/Shaarli.git] / application / front / controller / visitor / ErrorController.php
CommitLineData
0c6fdbe1
A
1<?php
2
3declare(strict_types=1);
4
5namespace Shaarli\Front\Controller\Visitor;
6
7use Shaarli\Front\Exception\ShaarliFrontException;
8use Slim\Http\Request;
9use Slim\Http\Response;
10
11/**
12 * Controller used to render the error page, with a provided exception.
13 * It is actually used as a Slim error handler.
14 */
15class ErrorController extends ShaarliVisitorController
16{
17 public function __invoke(Request $request, Response $response, \Throwable $throwable): Response
18 {
19 // Unknown error encountered
20 $this->container->pageBuilder->reset();
21
22 if ($throwable instanceof ShaarliFrontException) {
23 // Functional error
24 $this->assignView('message', nl2br($throwable->getMessage()));
25
26 $response = $response->withStatus($throwable->getCode());
27 } else {
28 // Internal error (any other Throwable)
cfdd2094
A
29 if ($this->container->conf->get('dev.debug', false) || $this->container->loginManager->isLoggedIn()) {
30 $this->assignView('message', t('Error: ') . $throwable->getMessage());
31 $this->assignView(
32 'text',
33 '<a href="https://github.com/shaarli/Shaarli/issues/new">'
34 . t('Please report it on Github.')
35 . '</a>'
36 );
5c06c087 37 $this->assignView('stacktrace', exception2text($throwable));
0c6fdbe1
A
38 } else {
39 $this->assignView('message', t('An unexpected error occurred.'));
40 }
41
42 $response = $response->withStatus(500);
43 }
44
0c6fdbe1
A
45 return $response->write($this->render('error'));
46 }
47}