customize the error page from Play Framework

谁说胖子不能爱 提交于 2019-12-11 19:36:24

问题


In case there is a compilation or runtime issue in Play Framework, error is returned to the client on receiving HTTP request. Which part of Play Framework creates and send the HTML? Can I customize it? For eg., my code throws an Exception on application loading. I see the following page

I want to customize this page so that it looks/feels like website's page. Also, instead of HTML body, could I send a JSON body?

UPDATE Looking at the stack trace of my application, the application loading sequence seems to be

1) AkkaHttpServer.scala - calls val tryApp = applicationProvider.get 2) which calls case cl: ClassLoader => reload(cl) // New application classes in DevServerStart.scala 3) reload loads the application by calling loader.load but as my code throws an exception from there, it is caught by reload method.

Somewhere in the code execution, HttpErrorHandler's onDevServerError is called which uses the view views.html.defaultpages.devError. This view is hidden in IntelliJ. it is anyhow a read-only file, so I still can't figure out if it is possible for to customize this page. My other concern now is how the application will behave when I move to production mode.

来源:https://stackoverflow.com/questions/57431377/customize-the-error-page-from-play-framework

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!