feat: 剔除多余工具类
This commit is contained in:
+6
-6
@@ -1,9 +1,9 @@
|
||||
package cn.odboy.exception.handler;
|
||||
|
||||
import cn.hutool.core.exceptions.ExceptionUtil;
|
||||
import cn.odboy.exception.BadRequestException;
|
||||
import cn.odboy.exception.EntityExistException;
|
||||
import cn.odboy.exception.EntityNotFoundException;
|
||||
import cn.odboy.exception.util.ThrowableUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
@@ -26,7 +26,7 @@ public class GlobalExceptionHandler {
|
||||
@ExceptionHandler(Throwable.class)
|
||||
public ResponseEntity<ApiError> handleException(Throwable e) {
|
||||
// 打印堆栈信息
|
||||
log.error(ThrowableUtil.getStackTrace(e));
|
||||
log.error(ExceptionUtil.stacktraceToString(e));
|
||||
return buildResponseEntity(ApiError.error(e.getMessage()));
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ public class GlobalExceptionHandler {
|
||||
@ExceptionHandler(value = BadRequestException.class)
|
||||
public ResponseEntity<ApiError> badRequestException(BadRequestException e) {
|
||||
// 打印堆栈信息
|
||||
log.error(ThrowableUtil.getStackTrace(e));
|
||||
log.error(ExceptionUtil.stacktraceToString(e));
|
||||
return buildResponseEntity(ApiError.error(e.getStatus(), e.getMessage()));
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ public class GlobalExceptionHandler {
|
||||
@ExceptionHandler(value = EntityExistException.class)
|
||||
public ResponseEntity<ApiError> entityExistException(EntityExistException e) {
|
||||
// 打印堆栈信息
|
||||
log.error(ThrowableUtil.getStackTrace(e));
|
||||
log.error(ExceptionUtil.stacktraceToString(e));
|
||||
return buildResponseEntity(ApiError.error(e.getMessage()));
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ public class GlobalExceptionHandler {
|
||||
@ExceptionHandler(value = EntityNotFoundException.class)
|
||||
public ResponseEntity<ApiError> entityNotFoundException(EntityNotFoundException e) {
|
||||
// 打印堆栈信息
|
||||
log.error(ThrowableUtil.getStackTrace(e));
|
||||
log.error(ExceptionUtil.stacktraceToString(e));
|
||||
return buildResponseEntity(ApiError.error(NOT_FOUND.value(), e.getMessage()));
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ public class GlobalExceptionHandler {
|
||||
@ExceptionHandler(MethodArgumentNotValidException.class)
|
||||
public ResponseEntity<ApiError> handleMethodArgumentNotValidException(MethodArgumentNotValidException e) {
|
||||
// 打印堆栈信息
|
||||
log.error(ThrowableUtil.getStackTrace(e));
|
||||
log.error(ExceptionUtil.stacktraceToString(e));
|
||||
ObjectError objectError = e.getBindingResult().getAllErrors().get(0);
|
||||
String message = objectError.getDefaultMessage();
|
||||
if (objectError instanceof FieldError) {
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
package cn.odboy.exception.util;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
|
||||
/**
|
||||
* 异常工具
|
||||
*/
|
||||
public class ThrowableUtil {
|
||||
|
||||
/**
|
||||
* 获取堆栈信息
|
||||
*/
|
||||
public static String getStackTrace(Throwable throwable) {
|
||||
StringWriter sw = new StringWriter();
|
||||
try (PrintWriter pw = new PrintWriter(sw)) {
|
||||
throwable.printStackTrace(pw);
|
||||
return sw.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package cn.odboy.application.job.util;
|
||||
|
||||
import cn.hutool.core.exceptions.ExceptionUtil;
|
||||
import cn.hutool.extra.template.Template;
|
||||
import cn.hutool.extra.template.TemplateConfig;
|
||||
import cn.hutool.extra.template.TemplateEngine;
|
||||
@@ -8,7 +9,6 @@ import cn.odboy.application.job.mapper.QuartzLogMapper;
|
||||
import cn.odboy.application.job.service.QuartzJobService;
|
||||
import cn.odboy.application.tools.service.EmailService;
|
||||
import cn.odboy.context.SpringBeanHolder;
|
||||
import cn.odboy.exception.util.ThrowableUtil;
|
||||
import cn.odboy.model.job.domain.QuartzJob;
|
||||
import cn.odboy.model.job.domain.QuartzLog;
|
||||
import cn.odboy.model.tools.dto.EmailDto;
|
||||
@@ -79,7 +79,7 @@ public class ExecutionJob extends QuartzJobBean {
|
||||
quartzLog.setTime(times);
|
||||
// 任务状态 0:成功 1:失败
|
||||
quartzLog.setIsSuccess(false);
|
||||
quartzLog.setExceptionDetail(ThrowableUtil.getStackTrace(e));
|
||||
quartzLog.setExceptionDetail(ExceptionUtil.stacktraceToString(e));
|
||||
// 任务如果失败了则暂停
|
||||
if (quartzJob.getPauseAfterFailure() != null && quartzJob.getPauseAfterFailure()) {
|
||||
quartzJob.setIsPause(false);
|
||||
@@ -90,7 +90,7 @@ public class ExecutionJob extends QuartzJobBean {
|
||||
EmailService emailService = SpringBeanHolder.getBean(EmailService.class);
|
||||
// 邮箱报警
|
||||
if (StringUtil.isNoneBlank(quartzJob.getEmail())) {
|
||||
EmailDto emailDto = taskAlarm(quartzJob, ThrowableUtil.getStackTrace(e));
|
||||
EmailDto emailDto = taskAlarm(quartzJob, ExceptionUtil.stacktraceToString(e));
|
||||
emailService.sendEmail(emailDto);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user