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

Controller "FOS\RestBundle\Controller\ExceptionController" does neither exist as service nor as class. (500 Internal Server Error) #2196

Closed gmuehl closed 4 years ago

gmuehl commented 4 years ago

I have some serious Problems with the newest dev-master in Symfony 5, this is my Configuration that worked before the upgrade:

# Read the documentation: https://symfony.com/doc/master/bundles/FOSRestBundle/index.html
fos_rest:
  routing_loader:
    default_format: json
    include_format: false
  body_listener: true
  param_fetcher_listener:  true
  view:
    view_response_listener:  force
  format_listener:
    rules:
      - { path: ^/api, prefer_extension: true, fallback_format: json, priorities: [ json ] }
      # https://github.com/FriendsOfSymfony/FOSRestBundle/issues/650#issuecomment-31449035
      - { path: '^/', priorities: [ 'html', '*/*'], fallback_format: html, prefer_extension: true }
  exception:
    codes:
      'Doctrine\ORM\EntityNotFoundException': HTTP_NOT_FOUND
      'Symfony\Component\Form\Exception\AlreadySubmittedException': HTTP_CONFLICT

routing_loader seems deprecated, so i simply removed it. No Idea if i have to reconfigure it somehow, but the Main Problems are Exceptions:

If I force an Exception i am getting two serious errors:

This is reproducable in Symfony 5 with an empty Config. So, my Questions:

I Am pretty helpless at the Moment, looks like the Documentation is not updated.

gmuehl commented 4 years ago

Error is caused by a setting in framework.yaml

# Exceptions as JSON
error_controller: 'FOS\RestBundle\Controller\ExceptionController::showAction'
xabbuh commented 4 years ago

The ExceptionController has been removed for 3.0. The Symfony ErrorRenderer component should now be used to render exceptions. Do you use the Symfony serializer or the JMS serializer?

gmuehl commented 4 years ago

Symfony Serializer

xabbuh commented 4 years ago

Then not setting the error_controller option should fix it for you.