Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only render tip to error log if plain text renderer is used #3321

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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