Core: Call to undefined method HttpException::getClass()

Created on 22 Nov 2019  路  3Comments  路  Source: api-platform/core

API Platform version(s) affected: 2.5.2

Description
I have used '\ApiPlatform\CoreBridge\SymfonyBundle\Test\ApiTestCase' to do some functional tests and everything worked fine with api platform core version 2.5.0. After upgrading to v2.5.2 most of my tests started to throw the following exception:

1) App\Tests\Functional\RestApi\AccountResourceTest::testCreateAccountWithAnonymousUser
Error: Call to undefined method Symfony\Component\HttpKernel\Exception\HttpException::getClass()

/srv/app/vendor/api-platform/core/src/Action/ExceptionAction.php:53
/srv/app/vendor/symfony/http-kernel/HttpKernel.php:146
/srv/app/vendor/symfony/http-kernel/HttpKernel.php:68
/srv/app/vendor/symfony/http-kernel/EventListener/ErrorListener.php:59
/srv/app/vendor/api-platform/core/src/EventListener/ExceptionListener.php:52
/srv/app/vendor/symfony/event-dispatcher/Debug/WrappedListener.php:126
/srv/app/vendor/symfony/event-dispatcher/EventDispatcher.php:264
/srv/app/vendor/symfony/event-dispatcher/EventDispatcher.php:239
/srv/app/vendor/symfony/event-dispatcher/EventDispatcher.php:73
/srv/app/vendor/symfony/event-dispatcher/Debug/TraceableEventDispatcher.php:168
/srv/app/vendor/symfony/http-kernel/HttpKernel.php:207
/srv/app/vendor/symfony/http-kernel/HttpKernel.php:79
/srv/app/vendor/symfony/http-kernel/Kernel.php:201
/srv/app/vendor/symfony/http-kernel/Client.php:65
/srv/app/vendor/symfony/framework-bundle/Client.php:131
/srv/app/vendor/symfony/browser-kit/Client.php:404
/srv/app/vendor/api-platform/core/src/Bridge/Symfony/Bundle/Test/Client.php:124
/srv/app/tests/Functional/RestApi/AccountResourceTest.php:97

How to reproduce

    public function testCreateAccountWithAnonymousUser()
    {
        $client = self::createClient();
        $client->request('POST', '/api/users', [
            'json' => [ ]
        ]);
        $this->assertResponseStatusCodeSame(401);
    }

Possible Solution
I am not quiet sure though, but I can clearly see some changes on 'ApiPlatform\Core\Action\ExceptionAction' class.

Additional Context
Downgrading the the version to 2.5.0 solves the problem!

P.S. I wish I can be more helpful, but I am not that fluent in English! Sorry about that!

Most helpful comment

Fixed by https://github.com/api-platform/core/pull/3285. I'll tag a new release containing this fix tomorrow.

All 3 comments

After upgrading from 2.5.2 and symfony components to 4.4.* I just encountered a related problem due to the exception passed to ApiPlatform\Core\Action\ExceptionAction::__invoke() not being of the expected type.

After a bit of digging I spotted the main cause to be a tiny difference between Symfony\Component\HttpKernel\EventListener\ErrorListener and and the deprecated Symfony\Component\HttpKernel\EventListener\ExceptionListener - wheras the latter wraps the passed exception in a FlattenException (within duplicateRequest()) the former does not.

Now, as ApiPlatform\Core\EventListener\ExceptionListener::onKernelException() will (beginning at 2.5.2) invoke the former (if existing) the argument eventually passed to the exception action will be of the wrong type.

Though a downgrade to 2.5.1 fixes the problem I'm not quite sure how or where it should be appropriately solved.

Fixed by https://github.com/api-platform/core/pull/3285. I'll tag a new release containing this fix tomorrow.

@dunglas Thanks for the quick fix and release!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gustawdaniel picture gustawdaniel  路  3Comments

CvekCoding picture CvekCoding  路  3Comments

mahmoodbazdar picture mahmoodbazdar  路  3Comments

rockyweng picture rockyweng  路  3Comments

silverbackdan picture silverbackdan  路  3Comments