Skip to content

Commit 6df3952

Browse files
committed
feat(user): implement update rate limit exception handling and related logic
1 parent 53ce19c commit 6df3952

3 files changed

Lines changed: 24 additions & 2 deletions

File tree

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.ligg.common.exception;
2+
3+
/**
4+
* 更新操作频率超过限制时抛出
5+
*/
6+
public class UpdateRateLimitException extends RuntimeException {
7+
8+
public UpdateRateLimitException(String message) {
9+
super(message);
10+
}
11+
}

common/src/main/java/com/ligg/common/handler/GlobalExceptionHandler.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.ligg.common.exception.LoginExpiredException;
77
import com.ligg.common.exception.AuthenticationFailedException;
88
import com.ligg.common.exception.AuthorizationException;
9+
import com.ligg.common.exception.UpdateRateLimitException;
910
import com.ligg.common.exception.RateLimitExceededException;
1011
import com.ligg.common.exception.VerificationCodeException;
1112
import com.ligg.common.response.Result;
@@ -178,6 +179,15 @@ public ResponseEntity<Result<Void>> handleRateLimitExceeded(RateLimitExceededExc
178179
.body(Result.error(ResponseCode.TOO_MANY_REQUESTS, ResponseCode.TOO_MANY_REQUESTS.getMessage()));
179180
}
180181

182+
/**
183+
* 更新操作频率限制(正常 200,携带业务错误码)
184+
*/
185+
@ExceptionHandler(UpdateRateLimitException.class)
186+
public Result<Void> handleUpdateRateLimit(UpdateRateLimitException e) {
187+
log.warn("更新操作频率限制: {}", e.getMessage());
188+
return Result.error(ResponseCode.TOO_MANY_REQUESTS, e.getMessage());
189+
}
190+
181191
/**
182192
* 验证码过期
183193
*/

flow-client/src/main/java/com/ligg/flowclient/service/impl/UserServiceImpl.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import com.ligg.common.entity.UserEntity;
1010
import com.ligg.common.exception.AuthenticationFailedException;
1111
import com.ligg.common.exception.LoginExpiredException;
12+
import com.ligg.common.exception.UpdateRateLimitException;
1213
import com.ligg.common.exception.RateLimitExceededException;
1314
import com.ligg.common.response.FlowTokenVo;
1415
import com.ligg.common.storage.ObjectStorageService;
@@ -267,7 +268,7 @@ private void checkUserInfoUpdateDailyLimit(Long userId) {
267268
if (ttl > 0) {
268269
long minutes = ttl / 60;
269270
long seconds = ttl % 60;
270-
throw new IllegalArgumentException(
271+
throw new UpdateRateLimitException(
271272
"用户信息更新过于频繁,请 %d 分 %d 秒后再试".formatted(minutes, seconds)
272273
);
273274
}
@@ -279,7 +280,7 @@ private void checkAvatarUploadLimit(Long userId) {
279280
if (ttl > 0) {
280281
long minutes = ttl / 60;
281282
long seconds = ttl % 60;
282-
throw new IllegalArgumentException(
283+
throw new UpdateRateLimitException(
283284
"头像更新过于频繁,请 %d 分 %d 秒后再试".formatted(minutes, seconds)
284285
);
285286
}

0 commit comments

Comments
 (0)