Skip to content

Commit 907430c

Browse files
committed
fix errorMessage
1 parent b0dbd19 commit 907430c

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

backend/spring-boot/src/main/java/org/bugzkit/api/shared/ratelimit/RateLimitInterceptor.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,14 @@
3232
import org.springframework.stereotype.Controller;
3333
import org.springframework.web.method.HandlerMethod;
3434
import org.springframework.web.servlet.HandlerInterceptor;
35+
import tools.jackson.databind.ObjectMapper;
3536

3637
@Component
3738
public class RateLimitInterceptor implements HandlerInterceptor, SmartInitializingSingleton {
3839
private final MessageService messageService;
3940
private final RedisClient lettuceClient;
4041
private final ApplicationContext applicationContext;
42+
private final ObjectMapper objectMapper;
4143
private final Map<String, BucketConfiguration> configCache = new ConcurrentHashMap<>();
4244
private LettuceBasedProxyManager<String> proxyManager;
4345

@@ -50,10 +52,12 @@ public class RateLimitInterceptor implements HandlerInterceptor, SmartInitializi
5052
public RateLimitInterceptor(
5153
MessageService messageService,
5254
RedisClient lettuceClient,
53-
ApplicationContext applicationContext) {
55+
ApplicationContext applicationContext,
56+
ObjectMapper objectMapper) {
5457
this.messageService = messageService;
5558
this.lettuceClient = lettuceClient;
5659
this.applicationContext = applicationContext;
60+
this.objectMapper = objectMapper;
5761
}
5862

5963
@Override
@@ -124,6 +128,6 @@ private void writeRateLimitResponse(HttpServletResponse response, ConsumptionPro
124128
response.setStatus(status.value());
125129
response.setContentType(MediaType.APPLICATION_PROBLEM_JSON_VALUE);
126130
response.setHeader("Retry-After", String.valueOf(retryAfter));
127-
response.getWriter().write(errorMessage.toString());
131+
objectMapper.writeValue(response.getOutputStream(), errorMessage);
128132
}
129133
}

0 commit comments

Comments
 (0)