-
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.
Browse files
Browse the repository at this point in the history
feat: Exception에 예외코드를 추가한다.
- Loading branch information
Showing
10 changed files
with
113 additions
and
26 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
src/main/java/com/clova/anifriends/global/exception/AniFriendsException.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.clova.anifriends.global.exception; | ||
|
||
public abstract class AniFriendsException extends RuntimeException { | ||
|
||
private final ErrorCode errorCode; | ||
|
||
protected AniFriendsException(ErrorCode errorCode, String message) { | ||
super(message); | ||
this.errorCode = errorCode; | ||
} | ||
|
||
public String getErrorCode() { | ||
return errorCode.getValue(); | ||
} | ||
} |
6 changes: 3 additions & 3 deletions
6
src/main/java/com/clova/anifriends/global/exception/AuthenticationException.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 |
---|---|---|
@@ -1,8 +1,8 @@ | ||
package com.clova.anifriends.global.exception; | ||
|
||
public abstract class AuthenticationException extends RuntimeException { | ||
public abstract class AuthenticationException extends AniFriendsException { | ||
|
||
protected AuthenticationException(String message) { | ||
super(message); | ||
protected AuthenticationException(ErrorCode errorCode, String message) { | ||
super(errorCode, message); | ||
} | ||
} |
6 changes: 3 additions & 3 deletions
6
src/main/java/com/clova/anifriends/global/exception/AuthorizationException.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 |
---|---|---|
@@ -1,8 +1,8 @@ | ||
package com.clova.anifriends.global.exception; | ||
|
||
public abstract class AuthorizationException extends RuntimeException { | ||
public abstract class AuthorizationException extends AniFriendsException { | ||
|
||
protected AuthorizationException(String message) { | ||
super(message); | ||
protected AuthorizationException(ErrorCode errorCode, String message) { | ||
super(errorCode, message); | ||
} | ||
} |
6 changes: 3 additions & 3 deletions
6
src/main/java/com/clova/anifriends/global/exception/BadRequestException.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 |
---|---|---|
@@ -1,8 +1,8 @@ | ||
package com.clova.anifriends.global.exception; | ||
|
||
public abstract class BadRequestException extends RuntimeException{ | ||
public abstract class BadRequestException extends AniFriendsException { | ||
|
||
protected BadRequestException(String message) { | ||
super(message); | ||
protected BadRequestException(ErrorCode errorCode, String message) { | ||
super(errorCode, message); | ||
} | ||
} |
6 changes: 3 additions & 3 deletions
6
src/main/java/com/clova/anifriends/global/exception/ConflictException.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 |
---|---|---|
@@ -1,8 +1,8 @@ | ||
package com.clova.anifriends.global.exception; | ||
|
||
public abstract class ConflictException extends RuntimeException { | ||
public abstract class ConflictException extends AniFriendsException { | ||
|
||
protected ConflictException(String message) { | ||
super(message); | ||
protected ConflictException(ErrorCode errorCode, String message) { | ||
super(errorCode, message); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
src/main/java/com/clova/anifriends/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,37 @@ | ||
package com.clova.anifriends.global.exception; | ||
|
||
import com.clova.anifriends.EnumType; | ||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
|
||
@AllArgsConstructor(access = AccessLevel.PRIVATE) | ||
public enum ErrorCode implements EnumType { | ||
|
||
// 400 | ||
BAD_REQUEST("AF001"), // 잘못된 입력값 | ||
INVALID_AUTH_INFO("AF002"), // 아이디 비밀번호 매치 안됨 | ||
// 401 | ||
TOKEN_EXPIRED("AF101"), // 토큰 만료 | ||
UN_AUTHENTICATION("AF102"), // 인증 안됨 | ||
// 403 | ||
UN_AUTHORIZATION("AF301"), // 권한 없음 | ||
// 404 | ||
NOT_FOUND("AF401"), // 존재하지 않는 리소스 | ||
// 409 | ||
ALREADY_EXISTS("AF901"), // 이미 존재하는 리소스 | ||
CONCURRENCY("AF902"), // 선착순 마감 | ||
// 500 | ||
INTERNAL_SERVER_ERROR("AF999"); // 서버 내부 에러 | ||
|
||
private final String value; | ||
|
||
@Override | ||
public String getName() { | ||
return name(); | ||
} | ||
|
||
@Override | ||
public String getValue() { | ||
return value; | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
src/main/java/com/clova/anifriends/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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
package com.clova.anifriends.global.exception; | ||
|
||
public record ErrorResponse(String message) { | ||
public record ErrorResponse(String errorCode, String 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
6 changes: 3 additions & 3 deletions
6
src/main/java/com/clova/anifriends/global/exception/NotFoundException.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 |
---|---|---|
@@ -1,8 +1,8 @@ | ||
package com.clova.anifriends.global.exception; | ||
|
||
public abstract class NotFoundException extends RuntimeException { | ||
public abstract class NotFoundException extends AniFriendsException { | ||
|
||
protected NotFoundException(String message) { | ||
super(message); | ||
protected NotFoundException(ErrorCode errorCode, String message) { | ||
super(errorCode, 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