Skip to content

Commit cb1c0e9

Browse files
committed
[Feat]: 데이터베이스 제약조건 예외 추가
1 parent 912d153 commit cb1c0e9

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

back/src/main/java/com/back/global/exception/GlobalExceptionHandler.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import jakarta.validation.ConstraintViolationException;
1212
import lombok.extern.slf4j.Slf4j;
1313
import org.slf4j.MDC;
14+
import org.springframework.dao.DataIntegrityViolationException;
1415
import org.springframework.http.HttpStatus;
1516
import org.springframework.http.ProblemDetail;
1617
import org.springframework.http.converter.HttpMessageNotReadableException;
@@ -149,4 +150,17 @@ public ProblemDetail handleAccessDenied(AccessDeniedException ex, HttpServletReq
149150
req
150151
);
151152
}
153+
154+
@ExceptionHandler(DataIntegrityViolationException.class)
155+
public ProblemDetail handleDataIntegrityViolation(DataIntegrityViolationException ex, HttpServletRequest req) {
156+
String userMessage = "요청을 처리할 수 없습니다.";
157+
return ProblemDetails.of(
158+
HttpStatus.BAD_REQUEST,
159+
"DATA_INTEGRITY_VIOLATION",
160+
userMessage,
161+
"DATA_INTEGRITY_VIOLATION",
162+
Map.of(),
163+
req
164+
);
165+
}
152166
}

0 commit comments

Comments
 (0)