-
Notifications
You must be signed in to change notification settings - Fork 1
[feat] Discord Webhook 에러 알림 기능 구현 #103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughJava 코드에 Discord 웹훅 에러 알림 기능이 추가되었습니다. 새로운 DTO 레코드가 생성되어 Discord 웹훅 페이로드 구조를 정의하며, 글로벌 예외 처리기에서 예외 발생 시 Discord로 알림을 전송하도록 변경되었습니다. GitHub Actions 워크플로우의 Discord 성공 메시지도 일부 수정되었습니다. Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant Server
participant GlobalExceptionHandler
participant DiscordWebhook
Client->>Server: 요청 전송
Server-->>GlobalExceptionHandler: 예외 발생
GlobalExceptionHandler->>DiscordWebhook: 에러 정보 웹훅 전송 (develop 프로필일 때)
GlobalExceptionHandler-->>Client: 에러 응답 반환
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Assessment against linked issues
Assessment against linked issues: Out-of-scope changes(해당 사항 없음) Possibly related PRs
Poem
Note ⚡️ Unit Test Generation is now available in beta!Learn more here, or try it out under "Finishing Touches" below. 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 1
🧹 Nitpick comments (2)
src/main/java/com/wayble/server/common/exception/GlobalExceptionHandler.java (2)
90-100: Discord 전송 실패에 대한 로깅 개선 필요.Discord 웹훅 전송 실패 시
e.getMessage()만 로깅하고 있는데, 디버깅에 필요한 정보가 부족합니다. HTTP 상태 코드나 응답 내용도 함께 로깅하면 문제 해결에 도움이 됩니다.로깅 정보를 개선해보세요:
} catch (Exception e){ - log.error(e.getMessage()); + log.error("Discord 웹훅 전송 실패: {}, URL: {}", e.getMessage(), discordWebhookUrl, e); }
31-31: RestTemplate 빈 주입 권장.
new RestTemplate()로 인스턴스를 직접 생성하는 대신 Spring의 빈으로 관리하는 것이 좋습니다. 이렇게 하면 커넥션 풀링, 타임아웃 설정, 인터셉터 등을 구성할 수 있습니다.RestTemplate을 빈으로 주입받도록 변경:
- private final RestTemplate restTemplate = new RestTemplate(); + private final RestTemplate restTemplate;그리고 생성자에서 주입받거나 별도 Configuration 클래스에서 @bean으로 정의하세요.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
.github/workflows/cd-develop.yml(1 hunks)src/main/java/com/wayble/server/common/dto/DiscordWebhookPayload.java(1 hunks)src/main/java/com/wayble/server/common/exception/GlobalExceptionHandler.java(3 hunks)
🔇 Additional comments (4)
src/main/java/com/wayble/server/common/dto/DiscordWebhookPayload.java (1)
5-17: Discord 웹훅 구조체 설계가 잘 되어있습니다.Record 클래스를 사용하여 불변성과 간결함을 보장하고, Discord 웹훅 API의 중첩된 구조를 적절히 모델링했습니다. 필수 필드들(content, embeds, title, description 등)이 모두 포함되어 있어 완성도 높은 DTO입니다.
src/main/java/com/wayble/server/common/exception/GlobalExceptionHandler.java (2)
68-71: 프로파일 체크 로직이 정확합니다.
env.acceptsProfiles(Profiles.of("develop"))사용으로 develop 프로파일에서만 Discord 알림을 보내도록 제한한 것이 PR 목적에 부합합니다. 로컬 환경에서는 알림이 발송되지 않아 불필요한 노이즈를 방지할 수 있습니다.
33-37: Discord 웹훅 URL 설정 확인 필요application 설정 파일(application.yml/.properties 등)에서
discord.webhook-url프로퍼티가 누락된 것 같습니다.
@Value("${discord.webhook-url}")주입 시 해당 설정이 없으면 애플리케이션 구동 실패 또는 NullPointerException이 발생할 수 있습니다.
- 검토 대상:
src/main/java/com/wayble/server/common/exception/GlobalExceptionHandler.java(33행@Value("${discord.webhook-url}"))- 조치 제안:
- application-{profile}.yml/.properties에
discord.webhook-url추가@Value("${discord.webhook-url:}")와 같이 기본값 처리@ConditionalOnProperty(name="discord.webhook-url")활용설정 파일에 해당 프로퍼티가 올바르게 포함되어 있는지 확인 부탁드립니다.
.github/workflows/cd-develop.yml (1)
189-189: 브랜치 정보 확인 완료: 워크플로우는pull_request이벤트의branches: ["main"]에서 트리거되므로, Discord 메시지의 “브랜치: main” 변경은 적절합니다.
| DiscordWebhookPayload.Embed embed = new DiscordWebhookPayload.Embed( | ||
| "🚨 서버 에러 발생", | ||
| "```" + ex.getMessage() + "```", | ||
| timestamp, | ||
| List.of( | ||
| new DiscordWebhookPayload.Embed.Field("URL", path, false), | ||
| new DiscordWebhookPayload.Embed.Field("Status", status.toString(), true), | ||
| new DiscordWebhookPayload.Embed.Field("Time", timestamp, true), | ||
| new DiscordWebhookPayload.Embed.Field("Exception", ex.getClass().getSimpleName(), true) | ||
| ) | ||
| ); | ||
| DiscordWebhookPayload payload = new DiscordWebhookPayload(null, List.of(embed)); |
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
민감한 정보 노출 위험성 점검.
예외 메시지를 그대로 Discord로 전송하고 있는데, 스택 트레이스나 내부 시스템 정보가 포함될 수 있습니다. 보안상 민감한 정보가 외부로 노출될 위험이 있습니다.
예외 메시지를 필터링하거나 요약하는 로직을 추가하는 것을 고려해보세요:
- "```" + ex.getMessage() + "```",
+ "```" + sanitizeErrorMessage(ex.getMessage()) + "```",그리고 메시지 정화 메서드를 추가:
private String sanitizeErrorMessage(String message) {
if (message == null) return "Unknown error";
// 민감한 정보 패턴 제거 (예: SQL, 파일 경로, IP 주소 등)
return message.length() > 500 ? message.substring(0, 500) + "..." : message;
}🤖 Prompt for AI Agents
In src/main/java/com/wayble/server/common/exception/GlobalExceptionHandler.java
around lines 74 to 85, the exception message is sent directly to Discord,
risking exposure of sensitive information. To fix this, create a
sanitizeErrorMessage method that filters or truncates the message to remove
sensitive data or limit length, then replace ex.getMessage() with
sanitizeErrorMessage(ex.getMessage()) in the embed description. This ensures
only safe, summarized error details are sent externally.
✔️ 연관 이슈
📝 작업 내용
스크린샷 (선택)
Summary by CodeRabbit
신규 기능
기타