-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[feat] 예외처리 구축
- Loading branch information
Showing
14 changed files
with
180 additions
and
1 deletion.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
...ava/com/leets/xcellentbe/domain/chatroom/domain/exception/ChatRoomForbiddenException.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,11 @@ | ||
package com.leets.xcellentbe.domain.chatroom.domain.exception; | ||
|
||
import com.leets.xcellentbe.global.error.ErrorCode; | ||
import com.leets.xcellentbe.global.error.exception.CommonException; | ||
|
||
public class ChatRoomForbiddenException extends CommonException { | ||
public ChatRoomForbiddenException() { | ||
|
||
super(ErrorCode.CHAT_ROOM_FORBIDDEN); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...java/com/leets/xcellentbe/domain/chatroom/domain/exception/ChatRoomNotFoundException.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,11 @@ | ||
package com.leets.xcellentbe.domain.chatroom.domain.exception; | ||
|
||
import com.leets.xcellentbe.global.error.ErrorCode; | ||
import com.leets.xcellentbe.global.error.exception.CommonException; | ||
|
||
public class ChatRoomNotFoundException extends CommonException { | ||
public ChatRoomNotFoundException() { | ||
|
||
super(ErrorCode.CHAT_ROOM_NOT_FOUND); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/leets/xcellentbe/domain/post/exception/ArticleNotFoundException.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,11 @@ | ||
package com.leets.xcellentbe.domain.post.exception; | ||
|
||
import com.leets.xcellentbe.global.error.ErrorCode; | ||
import com.leets.xcellentbe.global.error.exception.CommonException; | ||
|
||
public class ArticleNotFoundException extends CommonException { | ||
public ArticleNotFoundException() { | ||
|
||
super(ErrorCode.ARTICLE_NOT_FOUND); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/leets/xcellentbe/domain/user/exception/UserNotFoundException.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,11 @@ | ||
package com.leets.xcellentbe.domain.user.exception; | ||
|
||
import com.leets.xcellentbe.global.error.ErrorCode; | ||
import com.leets.xcellentbe.global.error.exception.CommonException; | ||
|
||
public class UserNotFoundException extends CommonException { | ||
public UserNotFoundException() { | ||
|
||
super(ErrorCode.USER_NOT_FOUND); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/com/leets/xcellentbe/global/error/ErrorCode.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,23 @@ | ||
package com.leets.xcellentbe.global.error; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public enum ErrorCode { | ||
|
||
INVALID_INPUT_VALUE(400, "INVALID_INPUT_VALUE", "유효하지 않은 입력값입니다."), | ||
INVALID_TOKEN(401, "INVALID_TOKEN", "유효하지 않은 토큰입니다."), | ||
CHAT_ROOM_FORBIDDEN(403, "CHAT_ROOM_FORBIDDEN","권한이 없는 채팅방입니다."), | ||
EXPIRED_TOKEN(403, "EXPIRED_TOKEN", "만료된 토큰입니다."), | ||
ARTICLE_NOT_FOUND(404, "ARTICLE_NOT_FOUND", "게시물을 찾을 수 없습니다."), | ||
CHAT_ROOM_NOT_FOUND(404, "CHAT_ROOM_NOT_FOUND", "채팅방을 찾을 수 없습니다."), | ||
USER_NOT_FOUND(404, "USER_NOT_FOUND", "유저를 찾을 수 없습니다."), | ||
REJECT_DUPLICATION(409,"REJECT_DUPLICATION","중복된 값입니다."), | ||
INTERNAL_SERVER_ERROR(500, "INTERNAL_SERVER_ERROR", "서버 오류가 발생했습니다."); | ||
|
||
private final int status; | ||
private final String code; | ||
private final String message; | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/com/leets/xcellentbe/global/error/ErrorResponse.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,19 @@ | ||
package com.leets.xcellentbe.global.error; | ||
|
||
import lombok.Getter; | ||
|
||
@Getter | ||
public class ErrorResponse { | ||
private final int status; | ||
private final String message; | ||
private final String code; | ||
|
||
public ErrorResponse(ErrorCode errorCode) { | ||
this.status = errorCode.getStatus(); | ||
this.message = errorCode.getMessage(); | ||
this.code = errorCode.getCode(); | ||
} | ||
public static ErrorResponse of(ErrorCode errorCode) { | ||
return new ErrorResponse(errorCode); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/com/leets/xcellentbe/global/error/exception/CommonException.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,13 @@ | ||
package com.leets.xcellentbe.global.error.exception; | ||
|
||
import com.leets.xcellentbe.global.error.ErrorCode; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public class CommonException extends RuntimeException { | ||
|
||
private final ErrorCode errorCode; | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/com/leets/xcellentbe/global/error/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,25 @@ | ||
package com.leets.xcellentbe.global.error.exception; | ||
|
||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.ControllerAdvice; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
import com.leets.xcellentbe.global.error.*; | ||
|
||
@ControllerAdvice | ||
public class GlobalExceptionHandler { | ||
|
||
@ExceptionHandler(CommonException.class) // Custom Exception을 포괄적으로 처리 | ||
public ResponseEntity<ErrorResponse> handleCommonException(CommonException ex) { | ||
ErrorCode errorCode = ex.getErrorCode(); // 전달된 예외에서 에러 코드 가져오기 | ||
ErrorResponse errorResponse = new ErrorResponse(errorCode); | ||
return new ResponseEntity<>(errorResponse, HttpStatus.valueOf(errorCode.getStatus())); | ||
} | ||
|
||
@ExceptionHandler(Exception.class) | ||
public ResponseEntity<ErrorResponse> handleGenericException(Exception ex) { | ||
ErrorCode errorCode = ErrorCode.INTERNAL_SERVER_ERROR; | ||
ErrorResponse errorResponse = new ErrorResponse(errorCode); | ||
return new ResponseEntity<>(errorResponse, HttpStatus.INTERNAL_SERVER_ERROR); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/leets/xcellentbe/global/error/exception/custom/ExpiredTokenException.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,11 @@ | ||
package com.leets.xcellentbe.global.error.exception.custom; | ||
|
||
import com.leets.xcellentbe.global.error.ErrorCode; | ||
import com.leets.xcellentbe.global.error.exception.CommonException; | ||
|
||
public class ExpiredTokenException extends CommonException { | ||
public ExpiredTokenException() { | ||
|
||
super(ErrorCode.EXPIRED_TOKEN); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...java/com/leets/xcellentbe/global/error/exception/custom/InternalServerErrorException.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,11 @@ | ||
package com.leets.xcellentbe.global.error.exception.custom; | ||
|
||
import com.leets.xcellentbe.global.error.ErrorCode; | ||
import com.leets.xcellentbe.global.error.exception.CommonException; | ||
|
||
public class InternalServerErrorException extends CommonException { | ||
public InternalServerErrorException() { | ||
|
||
super(ErrorCode.INTERNAL_SERVER_ERROR); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...n/java/com/leets/xcellentbe/global/error/exception/custom/InvalidInputValueException.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,11 @@ | ||
package com.leets.xcellentbe.global.error.exception.custom; | ||
|
||
import com.leets.xcellentbe.global.error.ErrorCode; | ||
import com.leets.xcellentbe.global.error.exception.CommonException; | ||
|
||
public class InvalidInputValueException extends CommonException { | ||
public InvalidInputValueException() { | ||
|
||
super(ErrorCode.INVALID_INPUT_VALUE); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/leets/xcellentbe/global/error/exception/custom/InvalidTokenException.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,11 @@ | ||
package com.leets.xcellentbe.global.error.exception.custom; | ||
|
||
import com.leets.xcellentbe.global.error.ErrorCode; | ||
import com.leets.xcellentbe.global.error.exception.CommonException; | ||
|
||
public class InvalidTokenException extends CommonException { | ||
public InvalidTokenException() { | ||
|
||
super(ErrorCode.INVALID_TOKEN); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...n/java/com/leets/xcellentbe/global/error/exception/custom/RejectDuplicationException.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,11 @@ | ||
package com.leets.xcellentbe.global.error.exception.custom; | ||
|
||
import com.leets.xcellentbe.global.error.ErrorCode; | ||
import com.leets.xcellentbe.global.error.exception.CommonException; | ||
|
||
public class RejectDuplicationException extends CommonException { | ||
public RejectDuplicationException() { | ||
|
||
super(ErrorCode.REJECT_DUPLICATION); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -10,4 +10,4 @@ class XcellentBeApplicationTests { | |
void contextLoads() { | ||
} | ||
|
||
} | ||
} |