Skip to content

Commit

Permalink
fix: error traces without arguments (#5891)
Browse files Browse the repository at this point in the history
  • Loading branch information
soyuka committed Oct 17, 2023
1 parent 0c50d4c commit 51b8183
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/ApiResource/Error.php
Expand Up @@ -61,28 +61,35 @@ public function __construct(
private readonly string $title,
private readonly string $detail,
#[ApiProperty(identifier: true)] private int $status,
private readonly array $originalTrace,
array $originalTrace = null,
private ?string $instance = null,
private string $type = 'about:blank',
private array $headers = []
) {
parent::__construct();

if (!$originalTrace) {
return;
}

$this->originalTrace = [];
foreach ($originalTrace as $i => $t) {
unset($t['args']); // we don't want arguments in our JSON traces, especially with xdebug
$this->originalTrace[$i] = $t;
}
}

#[SerializedName('trace')]
#[Groups(['trace'])]
public ?array $originalTrace = null;

#[SerializedName('hydra:title')]
#[Groups(['jsonld', 'legacy_jsonld'])]
public function getHydraTitle(): string
{
return $this->title;
}

#[SerializedName('trace')]
#[Groups(['trace'])]
public function getOriginalTrace(): array
{
return $this->originalTrace;
}

#[SerializedName('hydra:description')]
#[Groups(['jsonld', 'legacy_jsonld'])]
public function getHydraDescription(): string
Expand Down
6 changes: 6 additions & 0 deletions src/Symfony/EventListener/ErrorListener.php
Expand Up @@ -67,7 +67,13 @@ public function __construct(
protected function duplicateRequest(\Throwable $exception, Request $request): Request
{
$dup = parent::duplicateRequest($exception, $request);

$apiOperation = $this->initializeOperation($request);

if ($this->debug) {
$this->logger?->error('An exception occured, transforming to an Error resource.', ['exception' => $exception, 'operation' => $apiOperation]);
}

$format = $this->getRequestFormat($request, $this->errorFormats, false);

if ($this->resourceMetadataCollectionFactory) {
Expand Down

0 comments on commit 51b8183

Please sign in to comment.