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 = {
@@ -17,11 +17,14 @@ export class WebhookController {
17
17
next : NextFunction ,
18
18
) : Promise < void > => {
19
19
try {
20
+ if ( ! req . body || typeof req . body !== 'object' || req . body . action !== "created" ) {
21
+ res . status ( 400 ) . json ( new EmptyResponseDto ( true , 'Sentry 웹훅 처리에 실패했습니다' , { } , null ) ) ;
22
+ }
23
+
20
24
const sentryData : SentryWebhookData = req . body ;
21
- if ( sentryData . action !== "created" ) res . status ( 400 ) . json ( new EmptyResponseDto ( true , 'Sentry 웹훅 처리에 실패했습니다' , { } , null ) ) ;
25
+
22
26
const slackMessage = this . formatSentryMessage ( sentryData ) ;
23
- console . log ( slackMessage ) ;
24
- // await sendSlackMessage(slackMessage);
27
+ await sendSlackMessage ( slackMessage ) ;
25
28
26
29
const response = new EmptyResponseDto ( true , 'Sentry 웹훅 처리에 성공하였습니다.' , { } , null ) ;
27
30
res . status ( 200 ) . json ( response ) ;
@@ -34,7 +37,7 @@ export class WebhookController {
34
37
private formatSentryMessage ( sentryData : SentryWebhookData ) : string {
35
38
const { data : { issue } } = sentryData ;
36
39
37
- if ( ! issue . status || ! issue . title || ! issue . culprit || ! issue . permalink || ! issue . id ) throw new Error ( 'Sentry 웹훅 데이터가 올바르지 않습니다' ) ;
40
+ if ( ! issue . status || ! issue . title || ! issue . culprit || ! issue . id ) throw new Error ( 'Sentry 웹훅 데이터가 올바르지 않습니다' ) ;
38
41
39
42
const { status, title : issueTitle , culprit, permalink, id } = issue ;
40
43
const statusEmoji = this . STATUS_EMOJI [ status as keyof typeof this . STATUS_EMOJI ] ;
0 commit comments