유효성 검사시에
@ExceptionHandler(MethodArgumentNotValidException.class)
public ResponseEntity<?> handleMethodArgumentNotValidException(MethodArgumentNotValidException ex) {
ExceptionDto body = ExceptionDto.of(7, "validation error");
return this.handleExceptionInternal(body, HttpStatus.BAD_REQUEST);
}
이와 같이 예외처리를 해주면 된다.
이 때 ex.getBindingResult().getAllErrors를 통해 유효성 검사시에 발생한 모든 에러를 가져올 수 있다.
'Spring Boot' 카테고리의 다른 글
QueryParameter Dto로 받기 (0) | 2024.12.10 |
---|---|
Presigned Url을 통한 파일 업로드 최적화 (0) | 2024.11.08 |
특정 서비스에서 타 서비스 기능 사용시 의존성 설정 (0) | 2024.09.25 |
모니터링 vs 가시성(Observability) (feat. OpenTelemetry) (0) | 2024.09.14 |
Spring Boot 페이지네이션(Page, Pageable) (0) | 2024.09.08 |