Skip to content

Commit f9c6a9e

Browse files
authored
Merge pull request #59 from M6Web/fix/support-type-error
fix: use Throwable instead of Exception in formatter
2 parents 623a8dd + db45dca commit f9c6a9e

2 files changed

Lines changed: 23 additions & 2 deletions

File tree

src/M6Web/Bundle/LogBridgeBundle/Formatter/ExceptionFormatter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function getLogContent(Request $request, Response $response, array $optio
4848
*
4949
* @return string
5050
*/
51-
protected function getExceptionTrace(\Exception $exception, $level = 1)
51+
protected function getExceptionTrace(\Throwable $exception, $level = 1)
5252
{
5353
$exceptionTrace = $this->formatException($exception, $level);
5454

@@ -64,7 +64,7 @@ protected function getExceptionTrace(\Exception $exception, $level = 1)
6464
*
6565
* @return string
6666
*/
67-
protected function formatException(\Exception $exception, $level = 1)
67+
protected function formatException(\Throwable $exception, $level = 1)
6868
{
6969
return
7070
"\nException class : \n------------------------\n".get_class($exception)."\n".

src/M6Web/Bundle/LogBridgeBundle/Tests/Units/Formatter/ExceptionFormatter.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,4 +149,25 @@ public function testProviderExceptionsDepth()
149149
->contains($exception3->getTraceAsString())
150150
;
151151
}
152+
153+
public function testTypeErrorException()
154+
{
155+
$request = new Request();
156+
$exception = new \TypeError('Test: TypeError exception thrown.');
157+
158+
$this
159+
->given(
160+
$request->attributes->add([$this->requestExceptionAttribute => $exception])
161+
)
162+
->if($provider = $this->createProvider())
163+
->then
164+
->object($provider->setTokenStorage($this->getMockedTokenStorage()))
165+
->isInstanceOf('M6Web\Bundle\LogBridgeBundle\Formatter\ExceptionFormatter')
166+
->string($provider->getLogContent($request, new Response('Body content response'), []))
167+
->contains('Exception message (1) :')
168+
->contains($exception->getMessage())
169+
->contains('Exception trace (1) :')
170+
->contains($exception->getTraceAsString())
171+
;
172+
}
152173
}

0 commit comments

Comments
 (0)