fix: 为部分异常捕捉添加错误日志展示

This commit is contained in:
paulGao 2022-09-13 11:33:39 +08:00
parent 322256cc5a
commit f375432e7d
3 changed files with 10 additions and 8 deletions

View File

@ -45,21 +45,20 @@ public class LimitInterceptor {
@Before("@annotation(limitPointAnnotation)")
public void interceptor(LimitPoint limitPointAnnotation) {
LimitTypeEnums limitTypeEnums = limitPointAnnotation.limitType();
String name = limitPointAnnotation.name();
String key;
int limitPeriod = limitPointAnnotation.period();
int limitCount = limitPointAnnotation.limit();
switch (limitTypeEnums) {
case CUSTOMER:
key = limitPointAnnotation.key();
break;
default:
key = limitPointAnnotation.key() + IpUtils
.getIpAddress(((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
if (limitTypeEnums == LimitTypeEnums.CUSTOMER) {
key = limitPointAnnotation.key();
} else {
key = limitPointAnnotation.key() + IpUtils
.getIpAddress(((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
}
ImmutableList<String> keys = ImmutableList.of(StringUtils.join(limitPointAnnotation.prefix(), key));
try {
Number count = redisTemplate.execute(limitScript, keys, limitCount, limitPeriod);
assert count != null;
log.info("限制请求{}, 当前请求{},缓存key{}", limitCount, count.intValue(), key);
//如果缓存里没有值或者他的值小于限制频率
if (count.intValue() >= limitCount) {
@ -72,6 +71,7 @@ public class LimitInterceptor {
} catch (ServiceException e) {
throw e;
} catch (Exception e) {
log.error("限流异常", e);
throw new ServiceException(ResultCode.ERROR);
}
}

View File

@ -47,6 +47,7 @@ public class PreventDuplicateSubmissionsInterceptor {
} catch (ServiceException e) {
throw e;
} catch (Exception e) {
log.error("防重复提交拦截器异常", e);
throw new ServiceException(ResultCode.ERROR);
}
}

View File

@ -96,6 +96,7 @@ public class VerificationServiceImpl implements VerificationService {
} catch (ServiceException e) {
throw e;
} catch (Exception e) {
log.error("生成验证码失败", e);
throw new ServiceException(ResultCode.ERROR);
}
}