Skip to content

Commit 81785ad

Browse files
committed
refactor: 은다님 제안 반영
1 parent 19bc8fb commit 81785ad

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

src/controllers/webhook.controller.ts

Lines changed: 8 additions & 5 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 = {
@@ -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];

src/types/models/Sentry.type.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,9 @@ export interface SentryWebhookData {
7070
data: {
7171
issue: SentryIssue;
7272
};
73+
actor: {
74+
type: string;
75+
id: string;
76+
name: string;
77+
};
7378
}

0 commit comments

Comments
 (0)