Skip to content

Commit

Permalink
Merge pull request #59 from M6Web/fix/support-type-error
Browse files Browse the repository at this point in the history
fix: use Throwable instead of Exception in formatter
  • Loading branch information
embaya authored Dec 17, 2020
2 parents 623a8dd + db45dca commit f9c6a9e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function getLogContent(Request $request, Response $response, array $optio
*
* @return string
*/
protected function getExceptionTrace(\Exception $exception, $level = 1)
protected function getExceptionTrace(\Throwable $exception, $level = 1)
{
$exceptionTrace = $this->formatException($exception, $level);

Expand All @@ -64,7 +64,7 @@ protected function getExceptionTrace(\Exception $exception, $level = 1)
*
* @return string
*/
protected function formatException(\Exception $exception, $level = 1)
protected function formatException(\Throwable $exception, $level = 1)
{
return
"\nException class : \n------------------------\n".get_class($exception)."\n".
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,25 @@ public function testProviderExceptionsDepth()
->contains($exception3->getTraceAsString())
;
}

public function testTypeErrorException()
{
$request = new Request();
$exception = new \TypeError('Test: TypeError exception thrown.');

$this
->given(
$request->attributes->add([$this->requestExceptionAttribute => $exception])
)
->if($provider = $this->createProvider())
->then
->object($provider->setTokenStorage($this->getMockedTokenStorage()))
->isInstanceOf('M6Web\Bundle\LogBridgeBundle\Formatter\ExceptionFormatter')
->string($provider->getLogContent($request, new Response('Body content response'), []))
->contains('Exception message (1) :')
->contains($exception->getMessage())
->contains('Exception trace (1) :')
->contains($exception->getTraceAsString())
;
}
}

0 comments on commit f9c6a9e

Please sign in to comment.