-
Notifications
You must be signed in to change notification settings - Fork 0
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
[016-HelpMS-리포지토리-구조변경]JPAException을 인프라로 옮기기 위해 SpringJPA를 상속받는 JPAR… #36
The head ref may contain hidden characters: "016-HelpMS-\uB9AC\uD3EC\uC9C0\uD1A0\uB9AC-\uAD6C\uC870\uBCC0\uACBD"
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
package com.example.checkinrequestMS.HelpAPI.domain.exceptions; | ||
package com.example.checkinrequestMS.HelpAPI.domain.exceptions.progress; | ||
|
||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Getter | ||
@RequiredArgsConstructor | ||
public enum ProgressErrorCode { | ||
; | ||
NO_PROGRESS("진행 정보가 존재하지 않습니다."); | ||
|
||
private final String detail; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.example.checkinrequestMS.HelpAPI.domain.exceptions.progress; | ||
|
||
import com.example.checkinrequestMS.common.exception.types.DomainException; | ||
|
||
public class ProgressException extends DomainException { | ||
|
||
public ProgressException(ProgressErrorCode errorCode) { | ||
super(errorCode.getDetail()); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.example.checkinrequestMS.HelpAPI.infra.aop.aspect; | ||
|
||
|
||
import com.example.checkinrequestMS.HelpAPI.infra.aop.exceptions.JPAException; | ||
import org.aspectj.lang.ProceedingJoinPoint; | ||
import org.aspectj.lang.annotation.Around; | ||
import org.aspectj.lang.annotation.Aspect; | ||
import org.springframework.stereotype.Component; | ||
|
||
import static com.example.checkinrequestMS.HelpAPI.infra.aop.exceptions.JPAErrorCode.*; | ||
|
||
@Component | ||
@Aspect | ||
public class JPAExceptionAspect { | ||
|
||
@Around("@annotation(JPARead)") | ||
public Object handleJPAReadException(ProceedingJoinPoint joinPoint) throws Throwable { | ||
try { | ||
return joinPoint.proceed(); | ||
} catch (Exception e) { | ||
throw new JPAException(ERROR_READ, e); | ||
|
||
} | ||
} | ||
|
||
@Around("@annotation(JPASave)") | ||
public Object handleJPASaveException(ProceedingJoinPoint joinPoint) throws Throwable { | ||
try { | ||
return joinPoint.proceed(); | ||
} catch (Exception e) { | ||
throw new JPAException(ERROR_SAVE, e); | ||
} | ||
} | ||
|
||
@Around("@annotation(JPAUpdate)") | ||
public Object handleJPAUpdateException(ProceedingJoinPoint joinPoint) throws Throwable { | ||
try { | ||
return joinPoint.proceed(); | ||
} catch (Exception e) { | ||
throw new JPAException(ERROR_UPDATE, e); | ||
} | ||
} | ||
|
||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.example.checkinrequestMS.HelpAPI.infra.aop.aspect; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target(ElementType.METHOD) | ||
public @interface JPARead { | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.example.checkinrequestMS.HelpAPI.infra.aop.aspect; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target(ElementType.METHOD) | ||
public @interface JPASave { | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.example.checkinrequestMS.HelpAPI.infra.aop.aspect; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target(ElementType.METHOD) | ||
public @interface JPAUpdate { | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.example.checkinrequestMS.HelpAPI.infra.aop.exceptions; | ||
|
||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Getter | ||
@RequiredArgsConstructor | ||
public enum JPAErrorCode { | ||
ERROR_SAVE("JPA 저장 작업 중 에러"), | ||
ERROR_UPDATE("JPA 업데이트 작업 중 에러"), | ||
ERROR_READ("JPA 조회 작업 중 에러"); | ||
Comment on lines
+8
to
+11
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 아하 jpaException을 만드신 이유는 어떤 작업을 하다가 발생했는지에 대한 메시지를 다르게 처리해주고 싶으셨던 것 같군요!
하지만 개발 환경에서는 어디서 에러가 발생했는지 알게되면 도움이 될 수 있을 것 같기도 하네요~ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 맞습니다. 개발자들에게만 메시지를 줄 수 있게 추후 HOTFIX로 업데이트 해 보겠습니다. (이슈) |
||
|
||
|
||
private final String detail; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.example.checkinrequestMS.HelpAPI.infra.aop.exceptions; | ||
|
||
import com.example.checkinrequestMS.common.exception.types.InfraException; | ||
|
||
public class JPAException extends InfraException { | ||
|
||
public JPAException(JPAErrorCode error) { | ||
super(error.getDetail()); | ||
} | ||
|
||
public JPAException(JPAErrorCode error, Exception e) { | ||
super(error.getDetail(), e); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,25 @@ | ||
package com.example.checkinrequestMS.HelpAPI.infra.db.help; | ||
|
||
import com.example.checkinrequestMS.HelpAPI.domain.entities.help.child.CheckIn; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import com.example.checkinrequestMS.HelpAPI.infra.aop.aspect.JPARead; | ||
import com.example.checkinrequestMS.HelpAPI.infra.aop.aspect.JPASave; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.util.Optional; | ||
|
||
@Repository | ||
@RequiredArgsConstructor | ||
public class CheckInJPARepository { | ||
private final CheckInSpringJPARepository checkInSpringJPARepository; | ||
|
||
@JPASave | ||
public void save(CheckIn checkIn) { | ||
checkInSpringJPARepository.save(checkIn); | ||
} | ||
@JPARead | ||
public Optional<CheckIn> findById(Long id){ | ||
return checkInSpringJPARepository.findById(id); | ||
} | ||
|
||
public interface CheckInJPARepository extends JpaRepository<CheckIn, Long> { | ||
} |
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은 catch하지만 throwable은 그대로 throws 하고 있군요. catch에서 Throwable를 잡아야 모든 예외에 대해 JPAExcpetion으로 래핑되지 않을까요?
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.
맞습니다. 수정하도록 하겠습니다! (이슈)