|
|
@@ -1,22 +1,21 @@
|
|
|
package com.goafanti.common.error;
|
|
|
|
|
|
-import java.text.MessageFormat;
|
|
|
-
|
|
|
-import javax.annotation.Resource;
|
|
|
-import javax.servlet.http.HttpServletRequest;
|
|
|
-import javax.servlet.http.HttpServletResponse;
|
|
|
-
|
|
|
+import com.goafanti.common.bo.Error;
|
|
|
+import com.goafanti.common.bo.Result;
|
|
|
+import com.goafanti.common.utils.LoggerUtils;
|
|
|
+import com.goafanti.common.utils.StringUtils;
|
|
|
+import com.goafanti.core.shiro.filter.ShiroFilterUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.core.io.support.ResourcePropertySource;
|
|
|
+import org.springframework.web.multipart.MaxUploadSizeExceededException;
|
|
|
import org.springframework.web.servlet.ModelAndView;
|
|
|
import org.springframework.web.servlet.handler.SimpleMappingExceptionResolver;
|
|
|
|
|
|
-import com.goafanti.common.bo.Error;
|
|
|
-import com.goafanti.common.bo.Result;
|
|
|
-import com.goafanti.common.utils.LoggerUtils;
|
|
|
-import com.goafanti.common.utils.StringUtils;
|
|
|
-import com.goafanti.core.shiro.filter.ShiroFilterUtils;
|
|
|
+import javax.annotation.Resource;
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.text.MessageFormat;
|
|
|
|
|
|
public class SystemExceptionResolver extends SimpleMappingExceptionResolver{
|
|
|
@Resource(name = "errorResource")
|
|
|
@@ -50,7 +49,7 @@ public class SystemExceptionResolver extends SimpleMappingExceptionResolver{
|
|
|
return getModelAndView(viewName, ex, request);
|
|
|
} else {// JSON
|
|
|
Result res = new Result();
|
|
|
- res.getError().add(new Error(viewName,ex.getMessage()));
|
|
|
+ res.getError().add(new Error(viewName,ex.getMessage()));
|
|
|
shiroFilterUtils.out(response, res);
|
|
|
return null;
|
|
|
}
|
|
|
@@ -81,7 +80,13 @@ public class SystemExceptionResolver extends SimpleMappingExceptionResolver{
|
|
|
message = errorResource.getProperty(ex.getClass().getName());
|
|
|
}
|
|
|
error = new Error((String) message);
|
|
|
- } else {
|
|
|
+ }else if (ex instanceof MaxUploadSizeExceededException) {
|
|
|
+ Object message = errorResource.getProperty(ex.getMessage());
|
|
|
+ if (message == null) {
|
|
|
+ message = errorResource.getProperty(ex.getClass().getName());
|
|
|
+ }
|
|
|
+ error = new Error((String) message);
|
|
|
+ }else {
|
|
|
error = new Error((String) errorResource.getProperty(ex.getClass().getName()));
|
|
|
LoggerUtils.fmtError(getClass(), ex, "系统异常。",ex.getClass().getName());
|
|
|
}
|
|
|
@@ -98,5 +103,5 @@ public class SystemExceptionResolver extends SimpleMappingExceptionResolver{
|
|
|
public void setErrorResource(ResourcePropertySource errorResource) {
|
|
|
this.errorResource = errorResource;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
}
|