Skip to content

Commit

Permalink
Merge pull request #3321 from akrabat/3317-do-not-write-tips-message-…
Browse files Browse the repository at this point in the history
…to-formatted-output

Only render tip to error log if plain text renderer is used
  • Loading branch information
akrabat committed Jun 13, 2024
2 parents ad92887 + bb96d39 commit 8388b33
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Slim/Handlers/ErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ protected function writeToErrorLog(): void
{
$renderer = $this->callableResolver->resolve($this->logErrorRenderer);
$error = $renderer($this->exception, $this->logErrorDetails);
if (!$this->displayErrorDetails) {
if ($this->logErrorRenderer === PlainTextErrorRenderer::class && !$this->displayErrorDetails) {
$error .= "\nTips: To display error details in HTTP response ";
$error .= 'set "displayErrorDetails" to true in the ErrorHandler constructor.';
}
Expand Down
29 changes: 29 additions & 0 deletions tests/Handlers/ErrorHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,35 @@ public function testWriteToErrorLogShowTip()
$handler->__invoke($request, $exception, false, true, true);
}

public function testWriteToErrorLogDoesNotShowTipIfErrorLogRendererIsNotPlainText()
{
$request = $this
->createServerRequest('/', 'GET')
->withHeader('Accept', 'application/json');

$logger = $this->getMockLogger();

$handler = new ErrorHandler(
$this->getCallableResolver(),
$this->getResponseFactory(),
$logger
);

$handler->setLogErrorRenderer(HtmlErrorRenderer::class);

$logger->expects(self::once())
->method('error')
->willReturnCallback(static function (string $error) {
self::assertStringNotContainsString(
'set "displayErrorDetails" to true in the ErrorHandler constructor',
$error
);
});

$exception = new HttpNotFoundException($request);
$handler->__invoke($request, $exception, false, true, true);
}

public function testDefaultErrorRenderer()
{
$request = $this
Expand Down

0 comments on commit 8388b33

Please sign in to comment.