限流异常改名

This commit is contained in:
dushitaoyuan
2019-08-31 21:51:11 +08:00
parent 36f1543a21
commit ee58dc26ad
3 changed files with 5 additions and 6 deletions

View File

@@ -5,8 +5,8 @@ package com.taoyuanx.securitydemo.exception;
* @desc 限制访问异常 http状态码 429
* @date 2019/8/26
*/
public class RadioLimitException extends RuntimeException {
public RadioLimitException(String message) {
public class LimitException extends RuntimeException {
public LimitException(String message) {
super(message);
}
}

View File

@@ -8,7 +8,6 @@ import com.taoyuanx.securitydemo.utils.ResponseUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;
import org.springframework.web.HttpMediaTypeNotSupportedException;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.HandlerExceptionResolver;
@@ -54,7 +53,7 @@ public class SystemExceptionHandler implements HandlerExceptionResolver {
} else if (e instanceof HttpMediaTypeNotSupportedException) {
HttpMediaTypeNotSupportedException mediaEx = (HttpMediaTypeNotSupportedException) e;
result = ResultBuilder.failed(ResultCode.UN_SUPPORT_MEDIATYPE.code, "不支持该媒体类型:" + mediaEx.getContentType());
} else if (e instanceof RadioLimitException) {
} else if (e instanceof LimitException) {
httpStatus = HttpStatus.TOO_MANY_REQUESTS;
result = ResultBuilder.failed(ResultCode.TOO_MANY_REQUESTS.code, e.getMessage());
} else if (e instanceof JSONException) {

View File

@@ -3,7 +3,7 @@ package com.taoyuanx.securitydemo.security;
import com.google.common.collect.Maps;
import com.google.common.util.concurrent.RateLimiter;
import com.taoyuanx.securitydemo.exception.RadioLimitException;
import com.taoyuanx.securitydemo.exception.LimitException;
import com.taoyuanx.securitydemo.utils.RequestUtil;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.Signature;
@@ -63,7 +63,7 @@ public class RateLimitAspect {
private void handleRateLimit(RateLimit rateLimit, String methodName) throws Throwable {
RateLimiter rateLimiter = doGetRateLimiter(rateLimit, methodName);
if (!rateLimiter.tryAcquire()) {
throw new RadioLimitException("请求过于频繁,请稍后再试");
throw new LimitException("请求过于频繁,请稍后再试");
}
}