简体   繁体   中英

How to display exception text in a custom error page on Symfony?

I'm working on Symfony and I created a custom error page, following the instruction of the Symfony documentation.

So, I have my app/Ressources/TwigBundle/views/Exception/error.html.twig file. It works fine, but in my error view, I want to display the Exception text, so that if I do this in a controller:

throw new \Exception('Ooops !');

...i can display the value 'Ooops !' in my Twig View.

Do someone knows which Twig variable have this information ?

我终于找到了答案:Exception Message只能通过Twig错误模板中的exception.message变量访问。

@Maxime

Indeed that's the way i do it as well.

I just want to mentioned that I encountered the problem when using exception.message that some of the generic errors are also rendered in your custom error page which will lead to exception messages like

"No route found for GET /any_route_that_is_not_defined "

which is the default when calling a page that really does not exists by definition

I didn't found a way to surpress or translate these messages yet :/

Have a look at the Symfony doc on how to customize error pages .

You have the message in {{ status_text }} and the exception code in {{ status_code }} .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM