Skip to content

Commit 3ce78d7

Browse files
committed
refactor: 예외 처리 수정
1 parent 4ee3f53 commit 3ce78d7

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/controllers/webhook.controller.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { NextFunction, Request, RequestHandler, Response } from 'express';
22
import { EmptyResponseDto, SentryWebhookData } from '@/types';
33
import logger from '@/configs/logger.config';
44
import { sendSlackMessage } from '@/modules/slack/slack.notifier';
5+
import { BadRequestError } from '@/exception';
56

67
export class WebhookController {
78
private readonly STATUS_EMOJI = {
@@ -17,7 +18,7 @@ export class WebhookController {
1718
): Promise<void> => {
1819
try {
1920
if (req.body?.action !== "created") {
20-
const response = new EmptyResponseDto(true, 'Sentry 웹훅 처리에 실패했습니다', {}, null);
21+
const response = new BadRequestError('Sentry 웹훅 처리에 실패했습니다');
2122
res.status(400).json(response);
2223
return;
2324
}
@@ -38,7 +39,7 @@ export class WebhookController {
3839
private formatSentryMessage(sentryData: SentryWebhookData): string {
3940
const { data: { issue } } = sentryData;
4041

41-
if(!issue.status || !issue.title || !issue.culprit || !issue.id) throw new Error('Sentry 웹훅 데이터가 올바르지 않습니다');
42+
if(!issue.status || !issue.title || !issue.culprit || !issue.id) throw new BadRequestError('Sentry 웹훅 처리에 실패했습니다');
4243

4344
const { status, title: issueTitle, culprit, permalink, id } = issue;
4445
const statusEmoji = this.STATUS_EMOJI[status as keyof typeof this.STATUS_EMOJI];

src/middlewares/auth.middleware.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { NextFunction, Request, Response } from 'express';
22
import { isUUID } from 'class-validator';
33
import logger from '@/configs/logger.config';
44
import pool from '@/configs/db.config';
5-
import { DBError, InvalidTokenError } from '@/exception';
5+
import { CustomError, DBError, InvalidTokenError } from '@/exception';
66
import { VelogJWTPayload, User } from '@/types';
77
import crypto from "crypto";
88

@@ -92,7 +92,7 @@ function verifySignature(request: Request, res: Response, next: NextFunction) {
9292
hmac.update(bodyToVerify, "utf8");
9393
const digest = hmac.digest("hex");
9494

95-
if(digest !== sentrySignature) throw new Error(`유효하지 않은 시그니처 헤더입니다.`);
95+
if(digest !== sentrySignature) throw new CustomError("유효하지 않은 시그니처 헤더입니다.", "INVALID_SIGNATURE", 400);
9696

9797
next();
9898
} catch (error) {

0 commit comments

Comments
 (0)