-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#3 feat: Create GlobalException init settings
- Loading branch information
Showing
3 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
KnockKnock/src/main/java/com/example/knockknock/global/exception/GlobalErrorCode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.example.knockknock.global.exception; | ||
|
||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import org.springframework.http.HttpStatus; | ||
|
||
import static org.springframework.http.HttpStatus.*; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public enum GlobalErrorCode { | ||
// Member | ||
// 400 BAD_REQUEST - 잘못된 요청 | ||
NOT_VALID_EMAIL(BAD_REQUEST, "유효하지 않은 이메일 입니다."), | ||
PASSWORD_MISMATCH(BAD_REQUEST, "비밀번호가 일치하지 않습니다."), | ||
DUPLICATE_PASSWORD(BAD_REQUEST, "비밀번호가 동일합니다."), | ||
DUPLICATE_NICK_NAME(BAD_REQUEST, "닉네임이 동일합니다."), | ||
NOT_VALID_NICKNAME(BAD_REQUEST, "영문, 한글, 숫자를 포함한 2~ 16글자를 입력해 주세요."), | ||
NOT_VALID_PASSWORD(BAD_REQUEST, "영문, 숫자, 특수문자를 포함한 8~20 글자를 입력해 주세요."), | ||
NOT_VALID_PHONENUMBER(BAD_REQUEST, "11자리 이내의 번호를 '-'를 제외한 숫자만 입력해 주세요."), | ||
// 401 Unauthorized - 권한 없음 | ||
INVALID_TOKEN(UNAUTHORIZED, "토큰이 유효하지 않습니다"), | ||
// 404 Not Found - 찾을 수 없음 | ||
EMAIL_NOT_FOUND(NOT_FOUND, "존재하지 않는 이메일 입니다."), | ||
NEED_AGREE_REQUIRE_TERMS(NOT_FOUND, "필수 약관에 동의해 주세요"), | ||
USER_NOT_FOUND(NOT_FOUND, "등록된 사용자가 없습니다"), | ||
USERINFO_NOT_FOUND(NOT_FOUND, "등록된 사용자 정보가 없습니다"), | ||
// 409 CONFLICT : Resource 를 찾을 수 없음 | ||
DUPLICATE_EMAIL(CONFLICT, "중복된 이메일이 존재합니다"), | ||
EXPIRED_REFRESH_TOKEN(BAD_REQUEST, "쿠키에 토큰이 없습니다."), | ||
|
||
// Friend | ||
FRIEND_NOT_FOUND(NOT_FOUND, "등록된 친구가 없습니다"), | ||
|
||
// Notification | ||
NOTIFICATION_NOT_FOUND(NOT_FOUND, "등록된 연락 일정이 없습니다"), | ||
; | ||
|
||
|
||
|
||
private final HttpStatus httpStatus; | ||
private final String message; | ||
} |
10 changes: 10 additions & 0 deletions
10
KnockKnock/src/main/java/com/example/knockknock/global/exception/GlobalException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.example.knockknock.global.exception; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public class GlobalException extends RuntimeException { | ||
private final GlobalErrorCode errorCode; | ||
} |
20 changes: 20 additions & 0 deletions
20
KnockKnock/src/main/java/com/example/knockknock/global/exception/GlobalExceptionHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.example.knockknock.global.exception; | ||
|
||
import com.example.lablink.global.message.ResponseMessage; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
import org.springframework.web.bind.annotation.RestControllerAdvice; | ||
|
||
@Slf4j | ||
@RestControllerAdvice | ||
public class GlobalExceptionHandler { | ||
|
||
@ExceptionHandler(value = { GlobalException.class }) | ||
protected ResponseEntity<ResponseMessage> handleCustomException(GlobalException e) { | ||
log.error("handleCustomException throw CustomException : {}", e.getErrorCode()); | ||
return ResponseMessage.ErrorResponse(e.getErrorCode()); | ||
} | ||
|
||
} | ||
|