【发布时间】:2019-12-02 17:47:06
【问题描述】:
我使用FullAjaxExceptionHandlerFactory 来处理 ajax 和非 ajax 请求期间的异常。
FullAjaxExceptionHandler将透明地处理 ajax 请求期间的异常,其方式与同步(非 ajax)请求期间的异常完全相同。
我注意到,如果在同步请求期间发生异常,findExceptionRootCause(实际展开的方法)不会被调用。因此,web.xml 中定义的规则不会被应用,因为它们依赖于 FullAjaxExceptionHandler 展开。
这是否意味着我需要扩展 FullAjaxExceptionHandler 或者我缺少什么?
堆栈跟踪:
(非ajax请求)
javax.servlet.ServletException:
Caused by: javax.faces.view.facelets.TagAttributeException
Caused by: javax.el.ELException
Caused by: xxx.MyException
web.xml:
<context-param>
<param-name>org.omnifaces.EXCEPTION_TYPES_TO_UNWRAP</param-name>
<param-value>javax.servlet.ServletException,javax.faces.view.facelets.TagAttributeException,javax.el.ELException</param-value>
</context-param>
...
<error-page>
<exception-type>xxx.MyException</exception-type>
<location>/xxx/page-not-found.xhtml</location>
</error-page>
<error-page>
<error-code>500</error-code>
<location>/xxx/internal-server-error.xhtml</location>
</error-page>
*我记得ELException 可能会被省略,因为无论如何它都会被包含在内。为确定起见,我将异常之前的所有类型都包含在堆栈跟踪中。
结果:
/xxx/internal-server-error.xhtml 已显示
预期:
/xxx/page-not-found.xhtml 已显示
更新:
对于上面提到的异常,如果我定义<error-page>like
<error-page>
<exception-type>javax.faces.view.facelets.TagAttributeException</exception-type>
<location>/blueglue/templates/error/page-not-found.xhtml</location>
</error-page>
或
<error-page>
<exception-type>javax.servlet.ServletException</exception-type>
<location>/blueglue/templates/error/page-not-found.xhtml</location>
</error-page>
我会得到预期的结果 - 404 页面。
对于 javax.el.ELException 和 xxx.MyException,异常会导致 500 页面,这不是我所期望的。
【问题讨论】:
-
您检查过展示页面的“正常请求”部分吗?
-
@BalusC 我刚才做过 :) 介绍误导我认为这个处理程序对待 ajax 和非 ajax 异常是一样的。我在想
FullExceptionHandler + Ajax = FullAjaxExceptionHandler,但事实并非如此......