0

我创建了特定的 ExceptionMappingInterceptor,它应该处理应用程序中发生的所有异常。

public class DefaultExceptionHandlerAction extends ExceptionMappingInterceptor  {

@Override
protected void publishException(ActionInvocation invocation, ExceptionHolder exceptionHolder) {


    String message = "error msg";
    HttpServletResponse response = ServletActionContext.getResponse();
    try {
        response.reset();
    } catch (Exception e) {
        LOGGER.debug("Could not reset the response");
    }
    response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
    PrintWriter out = null;
    try {
        response.setCharacterEncoding("UTF-8");
        out = response.getWriter();
        out.print(message);
    } catch (IOException ioe) {
        LOGGER.error("IOException in printMessage : " + ioe.getMessage(), ioe);
    } finally {
        if (out != null) {
            out.flush();
            out.close();
        }
    }

}

所有的动作都是通过 ajax 调用的,所以在 js 中我有全局错误处理:

error : function(jqXHR, textStatus, errorThrown) {
     // all other errors
     var contentDialog = $("<div/>",{ "id":"contentDialog"});
     contentDialog.html(jqXHR.responseText);
     contentDialog.dialog({
           title : 'Erreur',
           modal : true,
           zIndex: 8888,
           resizable: false,
           close: function(event, ui) {
             $(this).dialog("destroy").remove();
           },
           buttons:{"OK": function() {
           $(this).dialog("close");}}
     });
},...

问题:所有未捕获的 java 异常都得到了很好的处理,我输入了错误:我的 js 中的函数。但是如果我强制 freemarker 异常,我可以看到我们将通过我的特定拦截器,但响应状态将正常,因此 ajax 不会进入错误:part.

我错过了什么?

谢谢

4

0 回答 0