This repository was archived by the owner on Jan 11, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
[FEATURE] ExternalApiException 내 resposeBody 필드 추가 및 에러 핸들링 추가
#36
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 9 additions & 1 deletion
10
src/main/java/com/example/spot/common/api/exception/base/ExternalApiException.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,15 @@ | ||
| package com.example.spot.common.api.exception.base; | ||
|
|
||
| public class ExternalApiException extends RuntimeException { | ||
| public ExternalApiException(String s, Exception e) { | ||
|
|
||
| private final String responseBody; | ||
|
|
||
| public ExternalApiException(String s, String body, Exception e) { | ||
| super(s, e); | ||
| this.responseBody = body; | ||
| } | ||
|
|
||
| public String getResponseBody() { | ||
| return responseBody; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,9 +14,10 @@ public static <T> T run(Supplier<T> call) { | |
| return call.get(); | ||
| } catch (FeignException e) { | ||
| String message = e.getMessage() != null ? e.getMessage() : ""; | ||
| String body = e.contentUTF8(); | ||
| String masked = mask(message); | ||
| throw new ExternalApiException( | ||
| "Feign API 호출 실패(" + e.status() + "): " + masked, e | ||
| "Feign API 호출 실패(" + e.status() + "): " + masked, body, e | ||
| ); | ||
|
Comment on lines
+17
to
21
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. Do not propagate raw external bodies to clients; sanitize + truncate first You’re passing Apply this diff to sanitize and bound the body: - String body = e.contentUTF8();
+ String body = e.contentUTF8();
+ String safeBody = mask(truncate(body, 2048)); // prevent PII leakage and huge payloads
String masked = mask(message);
throw new ExternalApiException(
- "Feign API 호출 실패(" + e.status() + "): " + masked, body, e
+ "Feign API 호출 실패(" + e.status() + "): " + masked, safeBody, e
);Add this helper in the class (outside the selected range): private static String truncate(String s, int max) {
if (s == null) return "";
return s.length() <= max ? s : s.substring(0, max);
}🤖 Prompt for AI Agents |
||
| } | ||
| } | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
🛠️ Refactor suggestion
Returning raw external response body to clients risks PII/secrets leakage
The handler currently returns
exception.getResponseBody()directly. If the upstream body contains tokens, cookies, emails, or stack traces, they will be exposed to clients. Given the sanitizer already exists in SafeFeignExecutor, either ensure that executor stores a sanitized/truncated body (preferred; see executor comment), or sanitize here before responding.Option A (preferred): rely on sanitized body from executor; then only ensure null-safety/truncation here:
Option B (alternate): derive HTTP status from the enum for consistency:
I can add unit tests for:
Would you like me to push a test commit?
📝 Committable suggestion