异常拦截

v1.4.1
Parker 4 years ago
parent bd9b5ec6af
commit a90e94bed0

@ -4,12 +4,16 @@ import lombok.extern.slf4j.Slf4j;
import org.opsli.common.api.ResultVo;
import org.opsli.common.exception.EmptyException;
import org.opsli.common.exception.ServiceException;
import org.opsli.core.msg.CoreMsg;
import org.springframework.core.annotation.Order;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import java.sql.SQLIntegrityConstraintViolationException;
import static org.opsli.common.constants.OrderConstants.EXCEPTION_HANDLER_ORDER;
/**
@ -58,4 +62,19 @@ public class GlobalExceptionHandler {
return errorR;
}
/**
*
*/
@ExceptionHandler(SQLIntegrityConstraintViolationException.class)
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
@ResponseBody
public ResultVo sqlIntegrityConstraintViolationException(EmptyException e) {
log.error("数据异常:{}",e.getMessage(),e);
ResultVo errorR = ResultVo.error(CoreMsg.MySQL_EXCEPTION_SQL_INTEGRITY_CONSTRAINT_VIOLATION.getMessage());
errorR.setCode(e.getCode());
return errorR;
}
}

@ -20,7 +20,12 @@ public enum CoreMsg implements BaseMsg {
/**
* Redis
*/
REDIS_EXCEPTION_PUSH_SUB(10200,"Redis 订阅通道失败!")
REDIS_EXCEPTION_PUSH_SUB(10200,"Redis 订阅通道失败!"),
/**
* MySQL
*/
MySQL_EXCEPTION_SQL_INTEGRITY_CONSTRAINT_VIOLATION(10300,"数据主键冲突或者已有该数据!"),
;

Loading…
Cancel
Save