Skip to content

Commit

Permalink
Normolize all child as well
Browse files Browse the repository at this point in the history
  • Loading branch information
GDXbsv committed Jul 25, 2022
1 parent 2dd1626 commit 2abf3af
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/Formatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ protected function normalizeException(\Throwable $e, int $depth = 0)
/** @var array{message: string, context?: array<string, mixed>} $data */
$data = parent::normalizeException($e, $depth);

$exceptionProviders = $this->exceptionContextProviderMap[\get_class($e)] ?? [];
$exceptionProviders = $this->getExceptionContexts($e);

foreach ($exceptionProviders as $exceptionProvider) {
/**
Expand All @@ -133,4 +133,21 @@ protected function normalizeException(\Throwable $e, int $depth = 0)

return $data;
}

/**
* @return array<callable>
*/
protected function getExceptionContexts(\Throwable $e): array {
if (isset($this->exceptionContextProviderMap[\get_class($e)])) {
return $this->exceptionContextProviderMap[\get_class($e)];
}
$exceptionContexts = [];
foreach (array_keys($this->exceptionContextProviderMap) as $className) {
if ($e instanceof $className) {
$exceptionContexts = array_merge($exceptionContexts + $this->exceptionContextProviderMap[$className]);
}
}

return $exceptionContexts;
}
}

0 comments on commit 2abf3af

Please sign in to comment.