refactor: 优化部分代码

修复 Sonar、Codacy 扫描问题
This commit is contained in:
2024-02-02 21:51:11 +08:00
parent 4558cf004b
commit 711bbe22aa
5 changed files with 14 additions and 11 deletions

View File

@@ -73,7 +73,9 @@ public class GlobalErrorHandler extends BasicErrorController {
} catch (IOException e) {
log.error("请求地址 [{}],默认错误处理时发生 IO 异常。", path, e);
}
log.error("请求地址 [{}],发生错误,错误信息:{}。", path, JSONUtil.toJsonStr(errorAttributeMap));
if (log.isErrorEnabled()) {
log.error("请求地址 [{}],发生错误,错误信息:{}。", path, JSONUtil.toJsonStr(errorAttributeMap));
}
return null;
}
@@ -84,7 +86,9 @@ public class GlobalErrorHandler extends BasicErrorController {
HttpStatus status = super.getStatus(request);
R<Object> result = R.fail(status.value(), (String)errorAttributeMap.get("error"));
result.setData(path);
log.error("请求地址 [{}],发生错误,错误信息:{}。", path, JSONUtil.toJsonStr(errorAttributeMap));
if (log.isErrorEnabled()) {
log.error("请求地址 [{}],发生错误,错误信息:{}。", path, JSONUtil.toJsonStr(errorAttributeMap));
}
return new ResponseEntity<>(BeanUtil.beanToMap(result), HttpStatus.OK);
}
}

View File

@@ -29,6 +29,7 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;
import org.springframework.core.Ordered;
import top.charles7c.continew.starter.core.constant.PropertiesConstants;
import top.charles7c.continew.starter.core.constant.StringConstants;
@@ -73,7 +74,7 @@ public class TraceAutoConfiguration {
FilterRegistrationBean<TLogServletFilter> registration = new FilterRegistrationBean<>();
registration.setFilter(new TLogServletFilter(traceProperties));
registration.addUrlPatterns(StringConstants.PATH_PATTERN_CURRENT_DIR);
registration.setOrder(FilterRegistrationBean.HIGHEST_PRECEDENCE);
registration.setOrder(Ordered.HIGHEST_PRECEDENCE);
return registration;
}

View File

@@ -64,10 +64,8 @@ public class FileUploadUtils {
String pathname = filePath + fileName;
File dest = new File(pathname).getCanonicalFile();
// 如果父路径不存在,自动创建
if (!dest.getParentFile().exists()) {
if (!dest.getParentFile().mkdirs()) {
log.error("Create upload file parent path failed.");
}
if (!dest.getParentFile().exists() && (!dest.getParentFile().mkdirs())) {
log.error("Create upload file parent path failed.");
}
// 文件写入
multipartFile.transferTo(dest);