core icon indicating copy to clipboard operation
core copied to clipboard

4.0 breaks error handling compatibility

Open ostrolucky opened this issue 1 year ago • 2 comments

API Platform version(s) affected: 4.x

Description
I can't seem to make our error handling integration tests pass on api-platform 4.x

How to reproduce
Here are the relevant parts of the configuration used in api-platform/core:3.*:

api_platform:
  use_symfony_listeners: true
  handle_symfony_errors: true

Test:

Scenario: Invalid request
    When I add "Content-Type" header equal to "application/ld+json"
    And I add "Accept" header equal to "application/json"
    And I send a "POST" request to "/api/bulk-resend-activation-mail" with body:
    """
     invalid input{
    """
    Then the response status code should be 400

api-platform/core: 3.x:

api-platform/core: 4.x: (click to enlarge)

Possible Solution

Additional Context

ostrolucky avatar Oct 15 '24 16:10 ostrolucky

Mhh you never reach this line right?

https://github.com/api-platform/core/blob/fcd9a0725fb9fab942b306e5d3cb0e96226ee63e/src/Symfony/EventListener/ExceptionListener.php#L50

Is your endpoint an API Resource?

Another lead would be that this patch https://github.com/api-platform/core/commit/7399fcf7eaf28cd649d137da1fdd54f69093e275 changes something in your case but I need to know if you reach the previous mentioned line first.

soyuka avatar Oct 16 '24 06:10 soyuka

It does trigger that line. Inside, exception is rethrown as BadRequestHttpException, but that one doesn't seem to be handled further.

And that endpoint is not an API resource.

ostrolucky avatar Oct 16 '24 07:10 ostrolucky

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Dec 15 '24 14:12 stale[bot]

I tried to reproduce at https://github.com/api-platform/core/commit/1096084e04e00bbfe80865db2ca95249c5f2dce1 but I successfully got a 400. To run the test:

USE_SYMFONY_LISTENERS=true vendor/bin/phpunit tests/Functional/Symfony/ErrorTest.php

Did I forgot something?

soyuka avatar Dec 16 '24 13:12 soyuka

Hmm indeed, it looks some change has fixed this meanwhile :\

ostrolucky avatar Jan 13 '25 13:01 ostrolucky