diff --git a/Slim/Handlers/ErrorHandler.php b/Slim/Handlers/ErrorHandler.php index e11eb0c53..689b4630b 100644 --- a/Slim/Handlers/ErrorHandler.php +++ b/Slim/Handlers/ErrorHandler.php @@ -260,7 +260,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.'; } diff --git a/tests/Handlers/ErrorHandlerTest.php b/tests/Handlers/ErrorHandlerTest.php index 9346f1c7e..b50dff4b3 100644 --- a/tests/Handlers/ErrorHandlerTest.php +++ b/tests/Handlers/ErrorHandlerTest.php @@ -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