Skip to content

Commit

Permalink
Fix error description formatting for NotFoundHttpException in EntityV…
Browse files Browse the repository at this point in the history
…alueResolver (#48)
  • Loading branch information
rela589n authored Nov 8, 2023
1 parent cfa4adb commit 1e89fdd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion EventListener/Kernel/ApiExceptionFormatterListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public function __invoke(ExceptionEvent $event): void
$errorName = BaseErrorNames::RESOURCE_NOT_FOUND;

if (preg_match('/^(.+) object not found by the @(.+) annotation\.$/', $message)
|| preg_match('/^(.+) object not found by (.+). The expression (.+) returned null\.$/', $message)) {
|| preg_match('/^(.+) object not found by (.+)\..*$/', $message)) {
$message = 'resource_not_found_exception_message';
}
break;
Expand Down
12 changes: 10 additions & 2 deletions Tests/EventListener/Kernel/ApiExceptionFormatterListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,17 @@ public function testOnKernelExceptionOnPaymentRequired(): void
self::assertInstanceOf(HttpException::class, $exceptionEvent->getThrowable());
}

public function testOnKernelExceptionWhenResourceNotFoundCausedByMapEntityAttribute(): void
public function resourceNotFoundExceptionMessageDataProvider(): array
{
return [
['"App\\Entity\\Event\\Event\" object not found by \"Symfony\\Bridge\\Doctrine\\ArgumentResolver\\EntityValueResolver\". The expression \"repository.findClosedEventById(id)\" returned null.'],
['"App\\Entity\\Event\\Event" object not found by "Symfony\\Bridge\\Doctrine\\ArgumentResolver\\EntityValueResolver".'],
];
}

/** @dataProvider resourceNotFoundExceptionMessageDataProvider */
public function testOnKernelExceptionWhenResourceNotFoundCausedByMapEntityAttribute(string $exceptionMessage): void
{
$exceptionMessage = '"App\\Entity\\Event\\Event\" object not found by \"Symfony\\Bridge\\Doctrine\\ArgumentResolver\\EntityValueResolver\". The expression \"repository.findClosedEventById(id)\" returned null.';
$httpException = new NotFoundHttpException($exceptionMessage);
$resourceNotFoundMessage = 'Resource not found';

Expand Down

0 comments on commit 1e89fdd

Please sign in to comment.