Skip to content

Commit 9db3759

Browse files
committed
refactor: 필요없는 코드 정리 및 로직 개선
1 parent 37f8b31 commit 9db3759

File tree

1 file changed

+11
-23
lines changed

1 file changed

+11
-23
lines changed

src/controllers/webhook.controller.ts

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { NextFunction, Request, RequestHandler, Response } from 'express';
22
import { EmptyResponseDto, SentryWebhookData } from '@/types';
33
import logger from '@/configs/logger.config';
4-
import { sendSlackMessage } from '@/modules/slack/slack.notifier';
4+
// import { sendSlackMessage } from '@/modules/slack/slack.notifier';
55

66
export class WebhookController {
77
private readonly STATUS_EMOJI = {
@@ -11,23 +11,17 @@ export class WebhookController {
1111
'archived': '📦',
1212
} as const;
1313

14-
private readonly ACTION_TEXT = {
15-
'created': '새로운 오류가 발생했습니다',
16-
'resolved': '오류가 해결되었습니다',
17-
'unresolved': '오류가 다시 발생했습니다',
18-
'ignored': '오류가 무시되었습니다',
19-
'assigned': '오류가 할당되었습니다',
20-
} as const;
21-
2214
handleSentryWebhook: RequestHandler = async (
2315
req: Request,
2416
res: Response,
2517
next: NextFunction,
2618
): Promise<void> => {
2719
try {
2820
const sentryData: SentryWebhookData = req.body;
21+
if(sentryData.action !== "created") res.status(400).json(new EmptyResponseDto(true, 'Sentry 웹훅 처리에 실패했습니다', {}, null));
2922
const slackMessage = this.formatSentryMessage(sentryData);
30-
await sendSlackMessage(slackMessage);
23+
console.log(slackMessage);
24+
// await sendSlackMessage(slackMessage);
3125

3226
const response = new EmptyResponseDto(true, 'Sentry 웹훅 처리에 성공하였습니다.', {}, null);
3327
res.status(200).json(response);
@@ -38,23 +32,17 @@ export class WebhookController {
3832
};
3933

4034
private formatSentryMessage(sentryData: SentryWebhookData): string {
41-
const { action, data } = sentryData || {};
42-
const issue = data?.issue || {};
35+
const { data: { issue } } = sentryData;
36+
37+
if(!issue.status || !issue.title || !issue.culprit || !issue.permalink || !issue.id) throw new Error('Sentry 웹훅 데이터가 올바르지 않습니다');
4338

44-
// 알 수 없는 액션에 대한 기본값 처리
45-
const actionText = this.ACTION_TEXT[action as keyof typeof this.ACTION_TEXT] || `오류 이벤트: ${action}`;
46-
47-
// 알 수 없는 상태에 대한 기본값 처리
48-
const statusEmoji = this.STATUS_EMOJI[issue.status as keyof typeof this.STATUS_EMOJI] || '❓';
49-
50-
const issueTitle = issue.title || '제목 없음';
51-
const culprit = issue.culprit || '위치 정보 없음';
52-
const permalink = issue.permalink;
39+
const { status, title: issueTitle, culprit, permalink, id } = issue;
40+
const statusEmoji = this.STATUS_EMOJI[status as keyof typeof this.STATUS_EMOJI];
5341

5442
// URL 생성 - permalink가 있으면 사용, 없으면 실제 프로젝트 URL 패턴으로 생성
55-
const detailUrl = permalink || `https://velog-dashboardv2.sentry.io/issues/${issue.id || 'unknown'}/`;
43+
const detailUrl = permalink || `https://velog-dashboardv2.sentry.io/issues/${id}/`;
5644

57-
let message = `🚨 *${actionText}*\n\n`;
45+
let message = `🚨 *새로운 오류가 발생하였습니다*\n\n`;
5846
message += `${statusEmoji} *제목:* ${issueTitle}\n\n`;
5947
message += `📍 *위치:* ${culprit}\n\n`;
6048
message += `🔗 *상세 보기:* ${detailUrl}`;

0 commit comments

Comments
 (0)