Question

My problem is the following:

throw new HttpException(422, "some message") doesn't work in Controllers.

However, throw new HttpException(404, "some message") works, as well as 400 (etc.)

Why can't I throw an HttpException with a 422 HTTP status code?

When I try to, I get a [200] response with the following debug info:

Fatal error: Uncaught exception 'ErrorException' with message 'Notice: Undefined offset: 422 in app\cache\dev\classes.php line 3079' in vendor\symfony\src\Symfony\Component\HttpKernel\Debug\ErrorHandler.php on line 67

( ! ) ErrorException: Notice: Undefined offset: 422 in app\cache\dev\classes.php line 3079 in vendor\symfony\src\Symfony\Component\HttpKernel\Debug\ErrorHandler.php on line 67

(I use FOSRESTBundle if it counts... and of course I cleared the cache)

Was it helpful?

Solution

HTTP status 422 was added only in version 2.1. The combination of the active debugging with the notice generated by Response::setStatusCode, generates this ugly exception. However it seems that during production there are no problems. However, my advice is do not use it.

In my opinion this behavior is unexpected and should be reported..

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top