Display error details even with dev.debug set to false
It makes more sense to display the error even if it's unexpected. Only for logged in users. Fixes #1606
This commit is contained in:
parent
48df9f45b8
commit
cfdd209440
5 changed files with 58 additions and 10 deletions
|
@ -26,8 +26,14 @@ public function __invoke(Request $request, Response $response, \Throwable $throw
|
|||
$response = $response->withStatus($throwable->getCode());
|
||||
} else {
|
||||
// Internal error (any other Throwable)
|
||||
if ($this->container->conf->get('dev.debug', false)) {
|
||||
$this->assignView('message', $throwable->getMessage());
|
||||
if ($this->container->conf->get('dev.debug', false) || $this->container->loginManager->isLoggedIn()) {
|
||||
$this->assignView('message', t('Error: ') . $throwable->getMessage());
|
||||
$this->assignView(
|
||||
'text',
|
||||
'<a href="https://github.com/shaarli/Shaarli/issues/new">'
|
||||
. t('Please report it on Github.')
|
||||
. '</a>'
|
||||
);
|
||||
$this->assignView('stacktrace', exception2text($throwable));
|
||||
} else {
|
||||
$this->assignView('message', t('An unexpected error occurred.'));
|
||||
|
@ -36,7 +42,6 @@ public function __invoke(Request $request, Response $response, \Throwable $throw
|
|||
$response = $response->withStatus(500);
|
||||
}
|
||||
|
||||
|
||||
return $response->write($this->render('error'));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1266,11 +1266,15 @@ form {
|
|||
margin: 70px 0 25px;
|
||||
}
|
||||
|
||||
a {
|
||||
color: var(--main-color);
|
||||
}
|
||||
|
||||
pre {
|
||||
margin: 0 20%;
|
||||
padding: 20px 0;
|
||||
text-align: left;
|
||||
line-height: .7em;
|
||||
line-height: 1em;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: Shaarli\n"
|
||||
"POT-Creation-Date: 2020-11-05 16:47+0100\n"
|
||||
"PO-Revision-Date: 2020-11-05 16:48+0100\n"
|
||||
"POT-Creation-Date: 2020-11-05 19:43+0100\n"
|
||||
"PO-Revision-Date: 2020-11-05 19:44+0100\n"
|
||||
"Last-Translator: \n"
|
||||
"Language-Team: Shaarli\n"
|
||||
"Language: fr_FR\n"
|
||||
|
@ -501,7 +501,15 @@ msgstr "mois"
|
|||
msgid "Monthly"
|
||||
msgstr "Mensuel"
|
||||
|
||||
#: application/front/controller/visitor/ErrorController.php:33
|
||||
#: application/front/controller/visitor/ErrorController.php:30
|
||||
msgid "Error: "
|
||||
msgstr "Erreur : "
|
||||
|
||||
#: application/front/controller/visitor/ErrorController.php:34
|
||||
msgid "Please report it on Github."
|
||||
msgstr "Merci de la rapporter sur Github."
|
||||
|
||||
#: application/front/controller/visitor/ErrorController.php:39
|
||||
msgid "An unexpected error occurred."
|
||||
msgstr "Une erreur inattendue s'est produite."
|
||||
|
||||
|
|
|
@ -50,7 +50,31 @@ public function testDisplayFrontExceptionError(): void
|
|||
}
|
||||
|
||||
/**
|
||||
* Test displaying error with any exception (no debug): only display an error occurred with HTTP 500.
|
||||
* Test displaying error with any exception (no debug) while logged in:
|
||||
* display full error details
|
||||
*/
|
||||
public function testDisplayAnyExceptionErrorNoDebugLoggedIn(): void
|
||||
{
|
||||
$request = $this->createMock(Request::class);
|
||||
$response = new Response();
|
||||
|
||||
// Save RainTPL assigned variables
|
||||
$assignedVariables = [];
|
||||
$this->assignTemplateVars($assignedVariables);
|
||||
|
||||
$this->container->loginManager->method('isLoggedIn')->willReturn(true);
|
||||
|
||||
$result = ($this->controller)($request, $response, new \Exception('abc'));
|
||||
|
||||
static::assertSame(500, $result->getStatusCode());
|
||||
static::assertSame('Error: abc', $assignedVariables['message']);
|
||||
static::assertContainsPolyfill('Please report it on Github', $assignedVariables['text']);
|
||||
static::assertArrayHasKey('stacktrace', $assignedVariables);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test displaying error with any exception (no debug) while logged out:
|
||||
* display standard error without detail
|
||||
*/
|
||||
public function testDisplayAnyExceptionErrorNoDebug(): void
|
||||
{
|
||||
|
@ -61,10 +85,13 @@ public function testDisplayAnyExceptionErrorNoDebug(): void
|
|||
$assignedVariables = [];
|
||||
$this->assignTemplateVars($assignedVariables);
|
||||
|
||||
$this->container->loginManager->method('isLoggedIn')->willReturn(false);
|
||||
|
||||
$result = ($this->controller)($request, $response, new \Exception('abc'));
|
||||
|
||||
static::assertSame(500, $result->getStatusCode());
|
||||
static::assertSame('An unexpected error occurred.', $assignedVariables['message']);
|
||||
static::assertArrayNotHasKey('text', $assignedVariables);
|
||||
static::assertArrayNotHasKey('stacktrace', $assignedVariables);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,13 +9,17 @@
|
|||
<div id="pageError" class="page-error-container center">
|
||||
<h2>{$message}</h2>
|
||||
|
||||
<img src="{$asset_path}/img/sad_star.png#" alt="">
|
||||
|
||||
{if="!empty($text)"}
|
||||
<p>{$text}</p>
|
||||
{/if}
|
||||
|
||||
{if="!empty($stacktrace)"}
|
||||
<pre>
|
||||
{$stacktrace}
|
||||
</pre>
|
||||
{/if}
|
||||
|
||||
<img src="{$asset_path}/img/sad_star.png#" alt="">
|
||||
</div>
|
||||
{include="page.footer"}
|
||||
</body>
|
||||
|
|
Loading…
Reference in a new issue