Skip to content
Prev Previous commit
Next Next commit
refactor: 예외 처리 수정
  • Loading branch information
six-standard committed Jul 6, 2025
commit 3ce78d7d09dd8caf97e09ba6402f9857fe0203fa
5 changes: 3 additions & 2 deletions src/controllers/webhook.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { NextFunction, Request, RequestHandler, Response } from 'express';
import { EmptyResponseDto, SentryWebhookData } from '@/types';
import logger from '@/configs/logger.config';
import { sendSlackMessage } from '@/modules/slack/slack.notifier';
import { BadRequestError } from '@/exception';

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

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

const { status, title: issueTitle, culprit, permalink, id } = issue;
const statusEmoji = this.STATUS_EMOJI[status as keyof typeof this.STATUS_EMOJI];
Expand Down
4 changes: 2 additions & 2 deletions src/middlewares/auth.middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { NextFunction, Request, Response } from 'express';
import { isUUID } from 'class-validator';
import logger from '@/configs/logger.config';
import pool from '@/configs/db.config';
import { DBError, InvalidTokenError } from '@/exception';
import { CustomError, DBError, InvalidTokenError } from '@/exception';
import { VelogJWTPayload, User } from '@/types';
import crypto from "crypto";

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

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

next();
} catch (error) {
Expand Down
Loading