// Path: src/main/java/org/smart4j/framework/FrameworkConstant.java
// public interface FrameworkConstant {
// 
//     String UTF_8 = "UTF-8";
// 
//     String CONFIG_PROPS = "smart.properties";
//     String SQL_PROPS = "smart-sql.properties";
// 
//     String PLUGIN_PACKAGE = "org.smart4j.plugin";
// 
//     String JSP_PATH = ConfigHelper.getString("smart.framework.app.jsp_path", "/WEB-INF/jsp/");
//     String WWW_PATH = ConfigHelper.getString("smart.framework.app.www_path", "/www/");
//     String HOME_PAGE = ConfigHelper.getString("smart.framework.app.home_page", "/index.html");
//     int UPLOAD_LIMIT = ConfigHelper.getInt("smart.framework.app.upload_limit", 10);
// 
//     String PK_NAME = "id";
// }
// 
// Path: src/main/java/org/smart4j/framework/mvc/fault/AuthcException.java
// public class AuthcException extends RuntimeException {
// 
//     public AuthcException() {
//         super();
//     }
// 
//     public AuthcException(String message) {
//         super(message);
//     }
// 
//     public AuthcException(String message, Throwable cause) {
//         super(message, cause);
//     }
// 
//     public AuthcException(Throwable cause) {
//         super(cause);
//     }
// }
// 
// Path: src/main/java/org/smart4j/framework/mvc/fault/AuthzException.java
// public class AuthzException extends RuntimeException {
// 
//     public AuthzException() {
//         super();
//     }
// 
//     public AuthzException(String message) {
//         super(message);
//     }
// 
//     public AuthzException(String message, Throwable cause) {
//         super(message, cause);
//     }
// 
//     public AuthzException(Throwable cause) {
//         super(cause);
//     }
// }


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.smart4j.framework.FrameworkConstant;
import org.smart4j.framework.mvc.HandlerExceptionResolver;
import org.smart4j.framework.mvc.fault.AuthcException;
import org.smart4j.framework.mvc.fault.AuthzException;
import org.smart4j.framework.util.WebUtil;
package org.smart4j.framework.mvc.impl;


/**
 * 默认 Handler 异常解析器
 *
 * @author huangyong
 * @since 2.3
 */
public class DefaultHandlerExceptionResolver implements HandlerExceptionResolver {

    private static final Logger logger = LoggerFactory.getLogger(DefaultHandlerExceptionResolver.class);

    @Override
    public void resolveHandlerException(HttpServletRequest request, HttpServletResponse response, Exception e) {
        // 判断异常原因
        Throwable cause = e.getCause();
        if (cause == null) {
            logger.error(e.getMessage(), e);
            return;
        }
        if (cause instanceof AuthcException) {
            // 分两种情况进行处理
            if (WebUtil.isAJAX(request)) {
                // 跳转到 403 页面
                WebUtil.sendError(HttpServletResponse.SC_FORBIDDEN, "", response);
            } else {
                // 重定向到首页
// Path: src/main/java/org/smart4j/framework/FrameworkConstant.java
// public interface FrameworkConstant {
// 
//     String UTF_8 = "UTF-8";
// 
//     String CONFIG_PROPS = "smart.properties";
//     String SQL_PROPS = "smart-sql.properties";
// 
//     String PLUGIN_PACKAGE = "org.smart4j.plugin";
// 
//     String JSP_PATH = ConfigHelper.getString("smart.framework.app.jsp_path", "/WEB-INF/jsp/");
//     String WWW_PATH = ConfigHelper.getString("smart.framework.app.www_path", "/www/");
//     String HOME_PAGE = ConfigHelper.getString("smart.framework.app.home_page", "/index.html");
//     int UPLOAD_LIMIT = ConfigHelper.getInt("smart.framework.app.upload_limit", 10);
// 
//     String PK_NAME = "id";
// }
// 
// Path: src/main/java/org/smart4j/framework/mvc/fault/AuthcException.java
// public class AuthcException extends RuntimeException {
// 
//     public AuthcException() {
//         super();
//     }
// 
//     public AuthcException(String message) {
//         super(message);
//     }
// 
//     public AuthcException(String message, Throwable cause) {
//         super(message, cause);
//     }
// 
//     public AuthcException(Throwable cause) {
//         super(cause);
//     }
// }
// 
// Path: src/main/java/org/smart4j/framework/mvc/fault/AuthzException.java
// public class AuthzException extends RuntimeException {
// 
//     public AuthzException() {
//         super();
//     }
// 
//     public AuthzException(String message) {
//         super(message);
//     }
// 
//     public AuthzException(String message, Throwable cause) {
//         super(message, cause);
//     }
// 
//     public AuthzException(Throwable cause) {
//         super(cause);
//     }
// }


// Path: src/main/java/org/smart4j/framework/mvc/impl/DefaultHandlerExceptionResolver.java
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.smart4j.framework.FrameworkConstant;
import org.smart4j.framework.mvc.HandlerExceptionResolver;
import org.smart4j.framework.mvc.fault.AuthcException;
import org.smart4j.framework.mvc.fault.AuthzException;
import org.smart4j.framework.util.WebUtil;

package org.smart4j.framework.mvc.impl;


/**
 * 默认 Handler 异常解析器
 *
 * @author huangyong
 * @since 2.3
 */
public class DefaultHandlerExceptionResolver implements HandlerExceptionResolver {

    private static final Logger logger = LoggerFactory.getLogger(DefaultHandlerExceptionResolver.class);

    @Override
    public void resolveHandlerException(HttpServletRequest request, HttpServletResponse response, Exception e) {
        // 判断异常原因
        Throwable cause = e.getCause();
        if (cause == null) {
            logger.error(e.getMessage(), e);
            return;
        }
        if (cause instanceof AuthcException) {
            // 分两种情况进行处理
            if (WebUtil.isAJAX(request)) {
                // 跳转到 403 页面
                WebUtil.sendError(HttpServletResponse.SC_FORBIDDEN, "", response);
            } else {
                // 重定向到首页
                WebUtil.redirectRequest(FrameworkConstant.HOME_PAGE, request, response);