11import { NextFunction , Request , RequestHandler , Response } from 'express' ;
22import { EmptyResponseDto , SentryWebhookData } from '@/types' ;
33import logger from '@/configs/logger.config' ;
4- // import { sendSlackMessage } from '@/modules/slack/slack.notifier';
4+ import { sendSlackMessage } from '@/modules/slack/slack.notifier' ;
55
66export class WebhookController {
77 private readonly STATUS_EMOJI = {
@@ -17,11 +17,14 @@ export class WebhookController {
1717 next : NextFunction ,
1818 ) : Promise < void > => {
1919 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+
2024 const sentryData : SentryWebhookData = req . body ;
21- if ( sentryData . action !== "created" ) res . status ( 400 ) . json ( new EmptyResponseDto ( true , 'Sentry 웹훅 처리에 실패했습니다' , { } , null ) ) ;
25+
2226 const slackMessage = this . formatSentryMessage ( sentryData ) ;
23- console . log ( slackMessage ) ;
24- // await sendSlackMessage(slackMessage);
27+ await sendSlackMessage ( slackMessage ) ;
2528
2629 const response = new EmptyResponseDto ( true , 'Sentry 웹훅 처리에 성공하였습니다.' , { } , null ) ;
2730 res . status ( 200 ) . json ( response ) ;
@@ -34,7 +37,7 @@ export class WebhookController {
3437 private formatSentryMessage ( sentryData : SentryWebhookData ) : string {
3538 const { data : { issue } } = sentryData ;
3639
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 웹훅 데이터가 올바르지 않습니다' ) ;
3841
3942 const { status, title : issueTitle , culprit, permalink, id } = issue ;
4043 const statusEmoji = this . STATUS_EMOJI [ status as keyof typeof this . STATUS_EMOJI ] ;
0 commit comments