Repository: slimphp/Slim (php)

Issue:
Using wrong flag to write to error log in ErrorHandler
In `ErrorHandler` at line [262](https://github.com/slimphp/Slim/blob/038fd5713d5a41636fdff0e8dcceedecdd17fc17/Slim/Handlers/ErrorHandler.php#L262), the condition is checked against the wrong flag.

the condition must check against `$this->logErrorDetails` rather than `$this->displayErrorDetails`. so the line would be:

`if (!$this->logErrorDetails) {`

If the bug is valid, I can create a pull request to fix it.

More details: It seems `writeToErrorLog()` is used to save the logs properly somewhere and `$this->displayErrorDetails` is used by the renderer to show the error details in realtime on the client

Pull request description:
Only render tip to error log if plain text renderer is used
If the logErrorRenderer is not the plain text renderer then we must not render the tips message as this will break the structured format of the message that's been rendered.

Closes #3317

Patch:
diff --git a/Slim/Handlers/ErrorHandler.php b/Slim/Handlers/ErrorHandler.php
index f9606e36..34c1eabf 100644
--- a/Slim/Handlers/ErrorHandler.php
+++ b/Slim/Handlers/ErrorHandler.php
@@ -259,7 +259,7 @@ class ErrorHandler implements ErrorHandlerInterface
     {
         $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.';
         }


Test patch:
diff --git a/tests/Handlers/ErrorHandlerTest.php b/tests/Handlers/ErrorHandlerTest.php
index 9346f1c7..b50dff4b 100644
--- a/tests/Handlers/ErrorHandlerTest.php
+++ b/tests/Handlers/ErrorHandlerTest.php
@@ -353,6 +353,35 @@ class ErrorHandlerTest extends TestCase
         $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