Skip to content

Commit 890b5d7

Browse files
authored
Merge pull request #37 from TaskFlow-CLAP/CLAP-67
CLAP-67 Domain 레이어 exception 분리
2 parents 6afb385 + 966d1f7 commit 890b5d7

File tree

6 files changed

+54
-21
lines changed

6 files changed

+54
-21
lines changed

src/main/java/clap/server/adapter/inbound/web/dto/admin/RegisterMemberRequest.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ public record RegisterMemberRequest(
1818
@NotNull
1919
MemberRole role,
2020
@NotBlank
21-
String departmentRole,
22-
@NotNull
23-
Long adminId
21+
String departmentRole
2422
) {
2523
}
2624

src/main/java/clap/server/domain/model/member/Member.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@ public Member(MemberInfo memberInfo, Boolean notificationEnabled, String imageUr
2828
this.password = password;
2929
}
3030

31-
public void register(Member Admin){
32-
this.notificationEnabled=null;
33-
this.imageUrl=null;
34-
this.memberStatus=MemberStatus.PENDING;
35-
this.password="";
31+
public void register(Member admin) {
32+
this.admin = admin;
33+
this.notificationEnabled = null;
34+
this.imageUrl = null;
35+
this.memberStatus = MemberStatus.PENDING;
36+
this.password = "";
3637
}
3738
}

src/main/java/clap/server/exception/ApplicationException.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
11
package clap.server.exception;
22

33
import clap.server.exception.code.BaseErrorCode;
4-
import lombok.Getter;
54

6-
@Getter
7-
public class ApplicationException extends RuntimeException {
8-
9-
private final BaseErrorCode code;
5+
public class ApplicationException extends BaseException {
106

117
public ApplicationException(BaseErrorCode code) {
12-
super(code.getMessage());
13-
this.code = code;
8+
super(code);
149
}
1510

1611
public static ApplicationException from(BaseErrorCode code) {
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package clap.server.exception;
2+
3+
import clap.server.exception.code.BaseErrorCode;
4+
import lombok.Getter;
5+
6+
7+
@Getter
8+
public abstract class BaseException extends RuntimeException {
9+
10+
private final BaseErrorCode code;
11+
12+
protected BaseException(BaseErrorCode code) {
13+
super(code.getMessage());
14+
this.code = code;
15+
}
16+
17+
public static <T extends BaseException> T from(BaseErrorCode code, Class<T> exceptionClass) {
18+
try {
19+
return exceptionClass.getConstructor(BaseErrorCode.class).newInstance(code);
20+
} catch (Exception e) {
21+
throw new RuntimeException("Could not create exception instance", e);
22+
}
23+
}
24+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package clap.server.exception;
2+
3+
import clap.server.exception.code.BaseErrorCode;
4+
5+
public class DomainException extends BaseException {
6+
7+
public DomainException(BaseErrorCode code) {
8+
super(code);
9+
}
10+
11+
public static DomainException from(BaseErrorCode code) {
12+
return new DomainException(code);
13+
}
14+
}

src/main/java/clap/server/exception/ExceptionAdvice.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,21 +76,22 @@ public ResponseEntity<Object> exception(Exception e, WebRequest request) {
7676
);
7777
}
7878

79-
@ExceptionHandler(value = ApplicationException.class)
80-
public ResponseEntity onThrowException(ApplicationException applicationException, HttpServletRequest request) {
81-
BaseErrorCode baseErrorCode = applicationException.getCode();
79+
@ExceptionHandler(value = { ApplicationException.class, DomainException.class })
80+
public ResponseEntity<Object> onThrowException(
81+
BaseException exception,
82+
HttpServletRequest request) {
8283

83-
return handleExceptionInternal(applicationException, baseErrorCode, null, request);
84+
BaseErrorCode baseErrorCode = exception.getCode();
85+
return handleExceptionInternal(exception, baseErrorCode, null, request);
8486
}
8587

8688
private ResponseEntity<Object> handleExceptionInternal(
87-
ApplicationException e,
89+
BaseException e,
8890
BaseErrorCode baseErrorCode,
8991
HttpHeaders headers,
9092
HttpServletRequest request
9193
) {
9294
String code = baseErrorCode.getCustomCode();
93-
9495
WebRequest webRequest = new ServletWebRequest(request);
9596

9697
return super.handleExceptionInternal(

0 commit comments

Comments
 (0)