Browse Source

refactor(servo): 优化异常处理和文件上传配置

- 注释掉 rcsService 的初始化方法
- 优化 multipartConfigElement 方法的代码格式
- 设置全局异常处理器,默认返回详细的错误信息
master
lizw-2015 6 months ago
parent
commit
46d74b1dcf
  1. 16
      servo/src/main/java/com/yvan/workbench/autoconfigure/AppAutoConfiguration.java

16
servo/src/main/java/com/yvan/workbench/autoconfigure/AppAutoConfiguration.java

@ -17,8 +17,10 @@ import org.clever.core.AppBasicsConfig;
import org.clever.core.AppContextHolder;
import org.clever.core.Assert;
import org.clever.core.ResourcePathUtils;
import org.clever.core.exception.ExceptionUtils;
import org.clever.core.json.jackson.JacksonConfig;
import org.clever.core.mapper.JacksonMapper;
import org.clever.core.model.response.ErrorResponse;
import org.clever.core.reflection.ReflectionsUtils;
import org.clever.core.task.StartupTaskBootstrap;
import org.clever.data.jdbc.JdbcBootstrap;
@ -33,6 +35,7 @@ import org.clever.web.config.HttpConfig;
import org.clever.web.config.WebConfig;
import org.clever.web.filter.*;
import org.clever.web.utils.ApplyWebConfig;
import org.clever.web.utils.GlobalExceptionHandler;
import org.springframework.boot.autoconfigure.AutoConfigureOrder;
import org.springframework.boot.context.properties.bind.Binder;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
@ -122,10 +125,10 @@ public class AppAutoConfiguration {
public MultipartConfigElement multipartConfigElement(AppBasicsConfig appBasicsConfig, WebConfig webConfig) {
HttpConfig.Multipart multipart = webConfig.getHttp().getMultipart();
return new MultipartConfigElement(
ResourcePathUtils.getAbsolutePath(appBasicsConfig.getRootPath(), multipart.getLocation()),
multipart.getMaxFileSize().toBytes(),
multipart.getMaxTotalRequestSize().toBytes(),
(int) multipart.getMaxInMemoryFileSize().toBytes()
ResourcePathUtils.getAbsolutePath(appBasicsConfig.getRootPath(), multipart.getLocation()),
multipart.getMaxFileSize().toBytes(),
multipart.getMaxTotalRequestSize().toBytes(),
(int) multipart.getMaxInMemoryFileSize().toBytes()
);
}
@ -193,6 +196,11 @@ public class AppAutoConfiguration {
@Bean
public FilterRegistrationBean<HttpFilter> exceptionHandlerFilter() {
GlobalExceptionHandler.setDefaultHandler((exception, request, response) -> {
ErrorResponse res = GlobalExceptionHandler.newErrorResponse(request, exception);
res.setError(ExceptionUtils.getStackTraceAsString(exception));
return res;
});
FilterRegistrationBean<HttpFilter> filterBean = new FilterRegistrationBean<>();
filterBean.setOrder(Ordered.HIGHEST_PRECEDENCE + 300);
filterBean.addUrlPatterns(PathConstants.ALL);

Loading…
Cancel
Save