-
Notifications
You must be signed in to change notification settings - Fork 3
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 #10 from Tave100Shot/9-feat-error-custom-setting
feat error custom setting Pr
- Loading branch information
Showing
7 changed files
with
131 additions
and
5 deletions.
There are no files selected for viewing
6 changes: 5 additions & 1 deletion
6
src/main/java/com/api/TaveShot/global/constant/OauthConstant.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
15 changes: 15 additions & 0 deletions
15
src/main/java/com/api/TaveShot/global/exception/ApiException.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,15 @@ | ||
package com.api.TaveShot.global.exception; | ||
|
||
public class ApiException extends RuntimeException { | ||
|
||
private final ErrorType errorType; | ||
|
||
public ApiException(ErrorType errorType) { | ||
super(errorType.getMessage()); | ||
this.errorType = errorType; | ||
} | ||
|
||
public ErrorType getErrorType() { | ||
return errorType; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/com/api/TaveShot/global/exception/ApiExceptionHandler.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.api.TaveShot.global.exception; | ||
|
||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
import org.springframework.web.bind.annotation.RestControllerAdvice; | ||
|
||
@RestControllerAdvice | ||
public class ApiExceptionHandler { | ||
|
||
@ExceptionHandler({ApiException.class}) | ||
public ResponseEntity<ApiExceptionResponse> handleApiException(ApiException e) { | ||
ErrorType errorType = e.getErrorType(); | ||
ApiExceptionResponse response = new ApiExceptionResponse( | ||
errorType.getStatus().value(), | ||
errorType.getErrorCode(), | ||
errorType.getMessage() | ||
); | ||
return ResponseEntity.status(errorType.getStatus()).body(response); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/com/api/TaveShot/global/exception/ApiExceptionResponse.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,17 @@ | ||
package com.api.TaveShot.global.exception; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@Builder | ||
@AllArgsConstructor | ||
public class ApiExceptionResponse { | ||
|
||
private int status; | ||
|
||
private String errorCode; | ||
|
||
private String message; | ||
} |
62 changes: 62 additions & 0 deletions
62
src/main/java/com/api/TaveShot/global/exception/ErrorType.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,62 @@ | ||
package com.api.TaveShot.global.exception; | ||
|
||
import static org.springframework.http.HttpStatus.*; | ||
|
||
import lombok.Getter; | ||
import lombok.ToString; | ||
import org.springframework.http.HttpStatus; | ||
|
||
@Getter | ||
@ToString | ||
public enum ErrorType { | ||
|
||
/** | ||
* Error Message Convention | ||
* | ||
* name : _(head) + Error Name status : HttpStatus | ||
* | ||
* errorCode : 400번 오류인 상황이 여러개 올텐데, 4001, 4002, 4003.. 이런식으로 설정 (해당 오류들은 MEMBER 와 관련된 400 오류들) | ||
* ex) Member Error, Http Status Code: 400 -> MEMBER_4000 | ||
* | ||
* message : 사람이 알아볼 수 있도록 작성 | ||
* ex) "인증이 필요합니다." | ||
*/ | ||
|
||
// ------------------------------------------ SERVER ------------------------------------------ | ||
_CANT_TRANCE_INSTANCE(INTERNAL_SERVER_ERROR, "SERVER_5000", "상수는 인스턴스화 할 수 없습니다."), | ||
_SERVER_USER_NOT_FOUND(INTERNAL_SERVER_ERROR, "SERVER_5001", "로그인이 성공한 소셜 로그인 유저가 DB에 존재하지 않을 수 없습니다."), | ||
|
||
|
||
// ---------------------------------------- JWT TOKEN ---------------------------------------- | ||
_JWT_PARSING_ERROR(BAD_REQUEST, "JWT_4001", "JWT 토큰 파싱 중 오류가 발생했습니다."), | ||
_JWT_EXPIRED(UNAUTHORIZED, "JWT_4010", "Jwt Token의 유효 기간이 만료되었습니다."), | ||
|
||
|
||
|
||
// ------------------------------------------ USER ------------------------------------------ | ||
_USER_NOT_FOUND(NOT_FOUND, "USER_4040", "제공된 토큰으로 사용자를 찾을 수 없습니다.") | ||
|
||
; | ||
|
||
private final HttpStatus status; | ||
private final String errorCode; | ||
private final String message; | ||
|
||
ErrorType(HttpStatus status, String errorCode, String message) { | ||
this.status = status; | ||
this.errorCode = errorCode; | ||
this.message = message; | ||
} | ||
|
||
public HttpStatus getStatus() { | ||
return status; | ||
} | ||
|
||
public String getErrorCode() { | ||
return errorCode; | ||
} | ||
|
||
public String getMessage() { | ||
return message; | ||
} | ||
} |
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
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