Skip to content

Commit

Permalink
[#109] Refactor: Custom Exception 구조 생성
Browse files Browse the repository at this point in the history
 - 최상위 CustomException인 BusinessException을 생성하고 그 하위 Exception으로 구조를 변경하였습니다.
 - User 생성시 validation에 실패하면 발생하는 Exception을 생성하였습니다.
  • Loading branch information
ksundong authored and beginin15 committed Mar 27, 2020
1 parent 397a050 commit 065ec1e
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.codesquad.team1.signup.api;

import com.codesquad.team1.signup.common.constants.ErrorMessages;
import com.codesquad.team1.signup.common.exception.UserCreateParameterInvalidException;
import com.codesquad.team1.signup.common.response.ErrorResponse;
import com.codesquad.team1.signup.common.exception.ForbiddenException;
import com.codesquad.team1.signup.common.exception.UnauthorizedException;
Expand Down Expand Up @@ -59,7 +60,7 @@ public User createUser(@RequestBody User user) {
if (user.validate()) {
return userRepository.save(user);
}
throw new InvalidParameterException(ErrorMessages.INVALID_PARAMETER);
throw new UserCreateParameterInvalidException(ErrorMessages.USER_CREATE_PARAMETER_INVALID);
}

@PostMapping("/login")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public class ErrorMessages {

public static final String FORBIDDEN = "접근 권한이 없습니다.";
public static final String UNAUTHORIZED = "로그인이 필요합니다.";
public static final String INVALID_PARAMETER = "Validation을 통과하지 못한 값 입니다.";
public static final String USER_CREATE_PARAMETER_INVALID = "Validation을 통과하지 못한 값 입니다.";

private ErrorMessages() {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.codesquad.team1.signup.common.exception;

public class BusinessException extends RuntimeException {

public BusinessException(String message) {
super(message);
}

}
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package com.codesquad.team1.signup.common.exception;

public class ForbiddenException extends RuntimeException {
public class ForbiddenException extends BusinessException {

public ForbiddenException(String message) {
super(message);
}

}
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package com.codesquad.team1.signup.common.exception;

public class UnauthorizedException extends RuntimeException {
public class UnauthorizedException extends BusinessException {

public UnauthorizedException(String message) {
super(message);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.codesquad.team1.signup.common.exception;

public class UserCreateParameterInvalidException extends BusinessException {

public UserCreateParameterInvalidException(String message) {
super(message);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.springframework.data.relational.core.mapping.MappedCollection;
import org.springframework.data.relational.core.mapping.Table;

import java.io.Serializable;
import java.time.LocalDate;
import java.util.List;
import java.util.Objects;
Expand All @@ -16,7 +17,7 @@
import static com.codesquad.team1.signup.common.constants.ValidationConstants.USER_PHONE_NUMBER_VALIDATION_PATTERN;

@Table("USERS")
public class User {
public class User implements Serializable {

enum Gender {
FEMALE,
Expand Down

0 comments on commit 065ec1e

Please sign in to comment.