1 24 package org.riotfamily.common.web.util; 25 26 import org.springframework.web.servlet.ModelAndView; 27 import org.springframework.web.servlet.handler.SimpleMappingExceptionResolver; 28 29 35 public class AdvancedMappingExceptionResolver 36 extends SimpleMappingExceptionResolver { 37 38 private String rootCaseAttribute = "rootCause"; 39 40 public void setRootCaseAttribute(String rootCaseAttribute) { 41 this.rootCaseAttribute = rootCaseAttribute; 42 } 43 44 protected ModelAndView getModelAndView(String viewName, Exception ex) { 45 logger.error("Unhandled exception", ex); 46 ModelAndView mv = super.getModelAndView(viewName, ex); 47 48 Throwable rootCause = ex; 49 while (rootCause.getCause() != null) { 50 rootCause = rootCause.getCause(); 51 } 52 mv.getModel().put(rootCaseAttribute, rootCause); 53 54 return mv; 55 } 56 57 } 58 | Popular Tags |