package common.interceptor; import com.alibaba.fastjson.JSONObject; import com.jfinal.aop.Interceptor; import com.jfinal.aop.Invocation; import com.jfinal.core.Controller; import com.jfinal.json.FastJson; import common.utils.http.MyRet; public class ExceptionInterceptor implements Interceptor { @Override public void intercept(Invocation inv) { try { inv.invoke(); } catch (Exception e) { e.printStackTrace(); Controller c = inv.getController(); String requestJsonStr = (String) c.getRequest().getAttribute("data"); JSONObject requestJson = FastJson.getJson().parse(requestJsonStr, JSONObject.class); c.renderJson(MyRet.fail("Exception: " + e.getMessage()).setData(requestJson)); } } }