FriendsOfSymfony / FOSRestBundle

This Bundle provides various tools to rapidly develop RESTful API's with Symfony
http://symfony.com/doc/master/bundles/FOSRestBundle/index.html
MIT License
2.79k stars 703 forks source link

Configuring ExceptionController in Symfony4 #2180

Closed engharb closed 4 years ago

engharb commented 4 years ago

Hi,

I am running the FOS_rest bundle in symfony4 and I configured the fos_rest.yml file with the exception handler.

In DEV/test stage the exception is handled correctly, but in the production environment I used to get i.e

ERROR: Uncaught PHP Exception Symfony\Component\HttpKernel\Exception\BadRequestHttpException

Is there something missing in the Symfony configuration or in the fos_rest.yml file?

# fos_rest.yml
fos_rest:
    body_converter:
        enabled: true
        validate: true
        validation_errors_argument: validationErrors # This is the default value

    param_fetcher_listener: force
    view:
        mime_types:
            json: ['application/json', 'application/json;version=1.0', 'application/json;version=1.1']
        view_response_listener: true
        formats:
            xml:  false
            json: true
        templating_formats:
            html: false
        serialize_null:       false

    routing_loader:
        default_format: json

    format_listener:
        rules:
            - { path: ^/, prefer_extension: true, fallback_format: json, priorities: [ json ] }
    exception:
        enabled: true
        exception_controller: 'App\Controller\BundleRestExceptionController::showAction'
        #exception_controller: 'fos_rest.exception.controller::showAction'

    allowed_methods_listener: true

    access_denied_listener:
        json: true
    body_listener: false

    serializer:
        version:              null
        groups:               []
        serialize_null:       false

    zone:
        - { path: ^/* }

OS: Linux PHP -v: 7.4

Tobion commented 4 years ago

Closing as the exception_controller is deprecated in 2.8. You need to upgrade to symfony error renderer. See also fos_rest.exception.serializer_error_renderer config