1
1
import { NextFunction , Request , RequestHandler , Response } from 'express' ;
2
2
import { EmptyResponseDto , SentryWebhookData } from '@/types' ;
3
3
import logger from '@/configs/logger.config' ;
4
- import { sendSlackMessage } from '@/modules/slack/slack.notifier' ;
4
+ // import { sendSlackMessage } from '@/modules/slack/slack.notifier';
5
5
6
6
export class WebhookController {
7
7
private readonly STATUS_EMOJI = {
@@ -11,23 +11,17 @@ export class WebhookController {
11
11
'archived' : '📦' ,
12
12
} as const ;
13
13
14
- private readonly ACTION_TEXT = {
15
- 'created' : '새로운 오류가 발생했습니다' ,
16
- 'resolved' : '오류가 해결되었습니다' ,
17
- 'unresolved' : '오류가 다시 발생했습니다' ,
18
- 'ignored' : '오류가 무시되었습니다' ,
19
- 'assigned' : '오류가 할당되었습니다' ,
20
- } as const ;
21
-
22
14
handleSentryWebhook : RequestHandler = async (
23
15
req : Request ,
24
16
res : Response ,
25
17
next : NextFunction ,
26
18
) : Promise < void > => {
27
19
try {
28
20
const sentryData : SentryWebhookData = req . body ;
21
+ if ( sentryData . action !== "created" ) res . status ( 400 ) . json ( new EmptyResponseDto ( true , 'Sentry 웹훅 처리에 실패했습니다' , { } , null ) ) ;
29
22
const slackMessage = this . formatSentryMessage ( sentryData ) ;
30
- await sendSlackMessage ( slackMessage ) ;
23
+ console . log ( slackMessage ) ;
24
+ // await sendSlackMessage(slackMessage);
31
25
32
26
const response = new EmptyResponseDto ( true , 'Sentry 웹훅 처리에 성공하였습니다.' , { } , null ) ;
33
27
res . status ( 200 ) . json ( response ) ;
@@ -38,23 +32,17 @@ export class WebhookController {
38
32
} ;
39
33
40
34
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 웹훅 데이터가 올바르지 않습니다' ) ;
43
38
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 ] ;
53
41
54
42
// 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 } /` ;
56
44
57
- let message = `🚨 *${ actionText } *\n\n` ;
45
+ let message = `🚨 *새로운 오류가 발생하였습니다 *\n\n` ;
58
46
message += `${ statusEmoji } *제목:* ${ issueTitle } \n\n` ;
59
47
message += `📍 *위치:* ${ culprit } \n\n` ;
60
48
message += `🔗 *상세 보기:* ${ detailUrl } ` ;
0 commit comments