-
Notifications
You must be signed in to change notification settings - Fork 0
[FEATURE] Feign 재시도 관련 설정 추가 #29
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| package com.example.spot.common.config; | ||
|
|
||
| import feign.Retryer; | ||
| import org.springframework.context.annotation.Bean; | ||
| import org.springframework.context.annotation.Configuration; | ||
|
|
||
| @Configuration | ||
| public class FeignRetryConfig { | ||
|
|
||
| @Bean | ||
| Retryer retryer() { | ||
| return new Retryer.Default(200, 800, 3); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -20,7 +20,7 @@ public static <T> T run(Supplier<T> call) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private static String extractMessage(FeignException e) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return e.responseBody() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .map(body -> new String(body.array())) // byte[] → String | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .map(body -> new String(body.array())) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .orElse(e.getMessage()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
21
to
24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix ByteBuffer decoding: array() is unsafe and ignores position/limit; specify charset Using new String(body.array()) can throw UnsupportedOperationException for direct/read-only buffers and may include extra bytes beyond the current view. Also relies on platform default charset. Decode using position/remaining and a defined charset. Apply this diff within extractMessage: - private static String extractMessage(FeignException e) {
- return e.responseBody()
- .map(body -> new String(body.array()))
- .orElse(e.getMessage());
- }
+ private static String extractMessage(FeignException e) {
+ return e.responseBody()
+ .map(buf -> {
+ var readOnly = buf.asReadOnlyBuffer();
+ byte[] bytes;
+ if (readOnly.hasArray()) {
+ int offset = readOnly.arrayOffset() + readOnly.position();
+ int length = readOnly.remaining();
+ bytes = java.util.Arrays.copyOfRange(readOnly.array(), offset, offset + length);
+ } else {
+ bytes = new byte[readOnly.remaining()];
+ readOnly.get(bytes);
+ }
+ return new String(bytes, java.nio.charset.StandardCharsets.UTF_8);
+ })
+ .orElse(e.getMessage());
+ }Note: This uses java.util.Arrays and java.nio.charset.StandardCharsets; import if desired or keep FQCNs as above. 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Verification agent
🧩 Analysis chain
Retry may not trigger on 5xx/429 without a RetryableException source
Feign retries only when a RetryableException is thrown (e.g., I/O errors by the client or via a custom ErrorDecoder). If you intend to retry on 5xx/429, also provide an ErrorDecoder that maps those statuses to RetryableException or use Resilience4j/Spring Retry.
Run this to check if such wiring already exists:
🏁 Script executed:
Length of output: 4916
Add a custom ErrorDecoder to trigger retries on HTTP 5xx/429
Currently you’ve defined a global Retryer in
FeignRetryConfig(src/main/java/com/example/spot/common/config/FeignRetryConfig.java:11), but there are no customErrorDecoderimplementations in the codebase. By default Feign only retries when aRetryableExceptionis thrown (typically on I/O errors), not on HTTP status codes.What to do:
ErrorDecoderbean that maps 429 and 5xx responses toRetryableException.@FeignClient(configuration = …)definitions.Example snippet:
🤖 Prompt for AI Agents