-
Notifications
You must be signed in to change notification settings - Fork 6
Week 2/gongmeda #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: week-2/Gongmeda
Are you sure you want to change the base?
Conversation
DongGeon0908
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
runtime에서 발생하는 exception을 별도로 핸들링히는 건 어ㄸ애요?
| import java.util.UUID | ||
|
|
||
| data class Task( | ||
| val uuid: UUID, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
여기서 바로, UUID.generate 히는 방법도 있을 것 같아요
|
|
||
| import org.slf4j.LoggerFactory | ||
|
|
||
| inline fun<reified T> T.logger() = LoggerFactory.getLogger(T::class.java)!! No newline at end of file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mu.KotlinLogging.logger
요 라이브러리를 찾아보시고 적용하시면 될 것 같아요
| } | ||
|
|
||
| @Transactional | ||
| override fun saveInBatch(tasks: List<Task>): Int { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
실패하면 어떻게 될까요??
너무 많은 요창을 한번에 처리하면 부하가 발생할 것 같아요
| fun findByUuid(uuid: UUID): TaskEntity? | ||
|
|
||
| @Query("select t from TaskEntity t order by t.createdAt asc") | ||
| fun findAllOrderByCreatedAtAsc(pageable: org.springframework.data.domain.Pageable): org.springframework.data.domain.Page<TaskEntity> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
jpa에서 해당 쿼리는 자동 생성 가능할건데, 네이티브 쿼리를 쓰신 이유가 궁금해요
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
저도 자동 생성되는 걸로 알고 메소드명을 저렇게 지은건데 빈 생성 오류가 나더라구요... 네이밍 스키마 잘 지킨 것 같은데 왜 그러는지 모르겠습니다ㅠ
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Gongmeda
repository에 선언하지 말고, 자동 생성된 findAll(Pageable pageable) 쓰는 건 어때요?
sort 내용은 Pageable에 담을 수 있을 것 같아요.
| } | ||
|
|
||
| @ExceptionHandler(Exception::class) | ||
| fun handleException(e: Exception): ResponseEntity<Any> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
모든 exception이 여기서 처리되는 걸까요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
넵 맞습니다. 실제 서버를 배포한다면 예상치 못한 오류라 하더라도 사용자에게 전달되는 메시지를 제한할 필요가 있다고 생각해서, 이를 적용하기 편하게 핸들러는 하나로 처리해놨습니다.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
위에서 말씀하신 "runtime에서 발생하는 exception을 별도로 핸들링"하는건 RuntimeException과 이를 상속받는 예외들에 대한 전용 핸들러를 만드는걸 제안하시는건가요? (@ExceptionHandler(RuntimeException::class))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
넵넵 예를 들어
BusinessException : RuntimeException 요렇게 만들고,
앞으로 우리 비즈니스에서 발생하는 RuntimeException은 해당 BusinessException을 통해 핸들링하는거죵!
BusinessException을 핸들링하는 로직도 있고, Exception을 핸들링하는 로직도 있으면 좋을 것 같아요.
물론, Exception 핸들링도 우리가 정의한 포맷으로 response되도록요.
| return ResponseEntity.status(errorCode.status).body(errorCode.message) | ||
| } | ||
|
|
||
| throw e |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이러면 500에러가 발생하고, 에러 반환값도 달라질 것 같네요
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
반환값 통일은 아직 안했습니다ㅠ 추가하겠습니다
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
넹넹!
구현 내용
TaskRepository.findByUuidOrNull로 메소드명 변경비고