core icon indicating copy to clipboard operation
core copied to clipboard

Custom exception/error handling with interfaces

Open SpiGAndromeda opened this issue 3 years ago • 1 comments

Description
The exception to status code feature is doing a good job in the handling of custom exceptions. The documentation mentions "expected exceptions" that can be converted to 400 messages. However, I couldn't find information what is "expected" and what is "unexpected" only by browsing through the code.

It would be really nice if API Platform would provide an Interface "ExpectedException" or something like that. I think some Symfony exceptions (and maybe other) are expected as well. Therefore wrapping this exceptions with a class that implements this interface could be necessary. The exception handling would have to be refactored to use this interface.

Custom exceptions could be handled a lot more appropriate with this feature.

Furthermore more interfaces the status codes that "require" more structured information such as 422 (constraint violations) could be created.

I suggest, we discuss the feature here. Of cause I would take part in the implementation if it should be implemented (without bc breaks).

SpiGAndromeda avatar Sep 11 '22 11:09 SpiGAndromeda

Maybe that improving the documentation would be enough? Usually you want our status codes, and the exception_to_status feature is designed for userland exceptions (yours).

soyuka avatar Sep 16 '22 10:09 soyuka

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 Nov 15 '22 11:11 stale[bot]