-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from CSID-DGU/develop
โป๏ธ [Refactor] ํฌํธํด๋ฆฌ์ค ์์ธ์กฐํ ์๋ฌ ์ฒ๋ฆฌ ์ถ๊ฐ
- Loading branch information
Showing
5 changed files
with
103 additions
and
1 deletion.
There are no files selected for viewing
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
13 changes: 13 additions & 0 deletions
13
src/main/java/dongguk/osori/global/exception/CustomException.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 dongguk.osori.global.exception; | ||
|
||
import lombok.Getter; | ||
|
||
@Getter | ||
public class CustomException extends RuntimeException { | ||
private final ErrorCode errorCode; | ||
|
||
public CustomException(ErrorCode errorCode) { | ||
super(errorCode.getMessage()); | ||
this.errorCode = errorCode; | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
src/main/java/dongguk/osori/global/exception/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,46 @@ | ||
package dongguk.osori.global.exception; | ||
|
||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Getter | ||
@RequiredArgsConstructor | ||
public enum ErrorCode { | ||
// global | ||
INVALID_INPUT_VALUE(400, "์๋ชป๋ ์ ๋ ฅ ๊ฐ์ ๋๋ค."), | ||
INTERNAL_SERVER_ERROR(500, "์๋ฒ ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค."), | ||
UNAUTHORIZED_ACCESS(401, "๊ถํ์ด ์์ต๋๋ค."), | ||
INVALID_REQUEST(400, "์๋ชป๋ ์์ฒญ์ ๋๋ค."), | ||
FORBIDDEN_ACCESS(403, "์ ๊ทผ ๊ถํ์ด ์์ต๋๋ค."), | ||
SESSION_EXPIRED(401, "์ธ์ ์ด ๋ง๋ฃ๋์์ต๋๋ค."), | ||
INVALID_REQUEST_BODY(400, "์์ฒญ ๋ณธ๋ฌธ์ด ์๋ชป๋์์ต๋๋ค."), | ||
MISSING_REQUIRED_FIELD(400, "ํ์ ํ๋๊ฐ ๋๋ฝ๋์์ต๋๋ค."), | ||
INVALID_DATA_FORMAT(400, "์ ํจํ์ง ์์ ๋ฐ์ดํฐ ํ์์ ๋๋ค."), | ||
INVALID_FIELD_VALUE(422, "์์ฒญ ๋ณธ๋ฌธ์ ๋ฐ์ดํฐ๊ฐ ์ ํจํ์ง ์์ต๋๋ค."), | ||
FIELD_VALIDATION_FAILED(422, "ํ๋ ๊ฐ ๊ฒ์ฆ์ ์คํจํ์ต๋๋ค."), | ||
UNSUPPORTED_MEDIA_TYPE(415, "์ง์ํ์ง ์๋ Content-Type์ ๋๋ค."), | ||
|
||
|
||
// user | ||
UNAUTHORIZED(403, "์ธ์ฆ๋์ง ์์ ์ฌ์ฉ์์ ๋๋ค."), | ||
USER_NOT_FOUND(404, "์ฌ์ฉ์๋ฅผ ์ฐพ์ ์ ์์ต๋๋ค."), | ||
SESSION_USER_NOT_FOUND(401, "์ธ์ ์ userId๊ฐ ์์ต๋๋ค."), | ||
COUPLE_ONLY_ACCESS(403, "์ปคํ์ธ ๊ฒฝ์ฐ์๋ง ์ ๊ทผํ ์ ์์ต๋๋ค."), | ||
|
||
// policy | ||
POLICY_NOT_FOUND(404, "ํด๋น ์ ์ฑ ์ ์ฐพ์ ์ ์์ต๋๋ค."), | ||
POLICY_ALREADY_EXISTS(409, "์ด๋ฏธ ์กด์ฌํ๋ ์ ์ฑ ์ ๋๋ค."), | ||
|
||
|
||
// comment | ||
COMMENT_NOT_FOUND(404, "๋๊ธ์ ์ฐพ์ ์ ์์ต๋๋ค."), | ||
COMMENT_DELETE_FORBIDDEN(403, "๋๊ธ ์ญ์ ๊ถํ์ด ์์ต๋๋ค."), | ||
|
||
// portfolio | ||
PORTFOLIO_NOT_FOUND(404, "ํฌํธํด๋ฆฌ์ค๋ฅผ ์ฐพ์ ์ ์์ต๋๋ค."), | ||
PORTFOLIO_ACCESS_FORBIDDEN(403, "ํด๋น ํฌํธํด๋ฆฌ์ค์ ์ ๊ทผํ ๊ถํ์ด ์์ต๋๋ค."); | ||
|
||
|
||
private final int status; | ||
private final String message; | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/dongguk/osori/global/exception/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,18 @@ | ||
package dongguk.osori.global.exception; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@Builder | ||
public class ErrorResponse { | ||
private final int status; | ||
private final String message; | ||
|
||
public static ErrorResponse of(ErrorCode errorCode) { | ||
return ErrorResponse.builder() | ||
.status(errorCode.getStatus()) | ||
.message(errorCode.getMessage()) | ||
.build(); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/dongguk/osori/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,23 @@ | ||
package dongguk.osori.global.exception; | ||
|
||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
import org.springframework.web.bind.annotation.RestControllerAdvice; | ||
|
||
@RestControllerAdvice | ||
public class GlobalExceptionHandler { | ||
|
||
@ExceptionHandler(CustomException.class) | ||
public ResponseEntity<ErrorResponse> handleCustomException(CustomException ex) { | ||
return ResponseEntity | ||
.status(ex.getErrorCode().getStatus()) | ||
.body(ErrorResponse.of(ex.getErrorCode())); | ||
} | ||
|
||
@ExceptionHandler(Exception.class) | ||
public ResponseEntity<ErrorResponse> handleException(Exception ex) { | ||
return ResponseEntity | ||
.status(ErrorCode.INTERNAL_SERVER_ERROR.getStatus()) | ||
.body(ErrorResponse.of(ErrorCode.INTERNAL_SERVER_ERROR)); | ||
} | ||
} |