3

For example, I converter an entity in my update method in a controller,

public function show(Post $post): Response

According to the spec,

If no Post object is found, a 404 Response is generated;

Symfony will return a 404 response directly, but it only applies for a dev environment.

In a prod environment, it only throws an unhandled exception error.

Fatal error: Uncaught Symfony\Component\HttpKernel\Exception\NotFoundHttpException: App\Entity\Post object not found by the @ParamConverter annotation.

How can I handle the exception in a prod environment?

yifei3212
  • 821
  • 1
  • 9
  • 28
  • Did you cleared the cache? `php bin/console cache:clear --env=prod` – Fabian Schmick Feb 27 '19 at 12:38
  • I've tried that, but it didn't work. I didn't handle the exception, so it will return 200 and a Fatal error in a prod env. – yifei3212 Feb 27 '19 at 22:32
  • Quick solution? Add defaults to that route and set your $post=null because then it will never intercept, because null value is allowed. Then you can check inside your controller (if you have more then one, where you have this problem, use traits) and throw whatever you want or redirect to whatever you want. – rebru Feb 28 '19 at 09:55
  • 2
    Thanks for the help. That sounds good to me, but I still wonder if there's a better solution. – yifei3212 Feb 28 '19 at 10:02

0 Answers0