-
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.
refactor : HttpStatus 코드 ExceptionHandler에서 반환하도록 수정(#122)
- Loading branch information
1 parent
5fecd36
commit bde04b0
Showing
8 changed files
with
24 additions
and
44 deletions.
There are no files selected for viewing
13 changes: 5 additions & 8 deletions
13
.../main/kotlin/com/bamyanggang/apimodule/domain/user/application/exception/AuthException.kt
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,26 +1,23 @@ | ||
package com.bamyanggang.apimodule.domain.user.application.exception | ||
|
||
import com.bamyanggang.commonmodule.exception.CustomException | ||
import org.springframework.http.HttpStatus | ||
import org.springframework.http.HttpStatusCode | ||
|
||
sealed class AuthException ( | ||
errorCode: Int, | ||
httpStatusCode: HttpStatusCode, | ||
message: String, | ||
) : CustomException(CODE_PREFIX, errorCode, httpStatusCode , message) { | ||
) : CustomException(CODE_PREFIX, errorCode, message) { | ||
|
||
class OAuthFailed(message: String = "OAuth 인증에 실패하였습니다.") : | ||
AuthException(errorCode = 1, httpStatusCode = HttpStatus.BAD_REQUEST, message = message) | ||
AuthException(errorCode = 1, message = message) | ||
|
||
class KakaoUserInfoRetrievalException(message: String = "카카오 사용자 정보를 가져오는데 실패했습니다.") : | ||
AuthException(errorCode = 2, httpStatusCode = HttpStatus.BAD_REQUEST, message = message) | ||
AuthException(errorCode = 2, message = message) | ||
|
||
class GoogleUserInfoRetrievalException(message: String = "구글 사용자 정보를 가져오는데 실패했습니다.") : | ||
AuthException(errorCode = 3, httpStatusCode = HttpStatus.BAD_REQUEST, message = message) | ||
AuthException(errorCode = 3, message = message) | ||
|
||
companion object { | ||
const val CODE_PREFIX = "AUTH" | ||
} | ||
|
||
} | ||
} |
6 changes: 1 addition & 5 deletions
6
Common-Module/src/main/kotlin/com/bamyanggang/commonmodule/exception/CustomException.kt
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,25 +1,21 @@ | ||
package com.bamyanggang.commonmodule.exception | ||
|
||
import org.springframework.http.HttpStatusCode | ||
|
||
abstract class CustomException( | ||
codePrefix: String = DEFAULT_CODE_PREFIX, | ||
errorCode: Int, | ||
httpStatusCode: HttpStatusCode, | ||
override val message: String = DEFAULT_MESSAGE, | ||
) : RuntimeException(message) { | ||
|
||
val code: String = "$codePrefix-${ | ||
errorCode.toString().padStart(DEFAULT_CODE_NUMBER_LENGTH, DEFAULT_CODE_NUMBER_PAD_CHAR) | ||
}" | ||
|
||
val httpStatusCode: HttpStatusCode = httpStatusCode | ||
|
||
companion object { | ||
const val DEFAULT_CODE_PREFIX = "UNKNOWN" | ||
const val DEFAULT_MESSAGE = "예상하지 못한 오류가 발생했습니다." | ||
const val DEFAULT_CODE_NUMBER_LENGTH = 3 | ||
const val DEFAULT_CODE_NUMBER_PAD_CHAR = '0' | ||
} | ||
|
||
} | ||
} |
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
7 changes: 2 additions & 5 deletions
7
...n/com/bamyanggang/domainmodule/domain/jobDescription/exception/JobDescriptionException.kt
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
11 changes: 4 additions & 7 deletions
11
...-Module/src/main/kotlin/com/bamyanggang/domainmodule/domain/tag/exception/TagException.kt
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
9 changes: 4 additions & 5 deletions
9
...ence/src/main/java/com/bamyanggang/persistence/common/exception/PersistenceException.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,19 +1,18 @@ | ||
package com.bamyanggang.persistence.common.exception; | ||
|
||
import com.bamyanggang.commonmodule.exception.CustomException; | ||
import org.springframework.http.HttpStatus; | ||
|
||
public class PersistenceException extends CustomException { | ||
public static final String CODE_PREFIX = "PERSISTENCE"; | ||
|
||
public PersistenceException(int errorCode, HttpStatus httpStatusCode, String message) { | ||
super(CODE_PREFIX, errorCode, httpStatusCode, message); | ||
public PersistenceException(int errorCode, String message) { | ||
super(CODE_PREFIX, errorCode, message); | ||
} | ||
|
||
public static class NotFound extends PersistenceException { | ||
public NotFound() { | ||
super(1, HttpStatus.NOT_FOUND, "해당 데이터를 찾을 수 없습니다."); | ||
super(1, "해당 데이터를 찾을 수 없습니다."); | ||
} | ||
} | ||
|
||
} | ||
} |
13 changes: 5 additions & 8 deletions
13
Support-Module/Jwt/src/main/kotlin/com/bamyanggang/jwt/exception/JwtException.kt
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,26 +1,23 @@ | ||
package com.bamyanggang.jwt.exception | ||
|
||
import com.bamyanggang.commonmodule.exception.CustomException | ||
import org.springframework.http.HttpStatus | ||
import org.springframework.http.HttpStatusCode | ||
|
||
sealed class JwtException( | ||
errorCode: Int, | ||
httpStatusCode: HttpStatusCode, | ||
message: String, | ||
) : CustomException(CODE_PREFIX, errorCode, httpStatusCode , message) { | ||
) : CustomException(CODE_PREFIX, errorCode, message) { | ||
|
||
class InvalidTokenException(message: String = "유효하지 않은 토큰입니다.") : | ||
JwtException(errorCode = 1, httpStatusCode = HttpStatus.BAD_REQUEST, message = message) | ||
JwtException(errorCode = 1, message = message) | ||
|
||
class ExpiredTokenException(message: String = "만료된 토큰입니다.") : | ||
JwtException(errorCode = 2, httpStatusCode = HttpStatus.BAD_REQUEST, message = message) | ||
JwtException(errorCode = 2, message = message) | ||
|
||
class TokenNotFoundException(message: String = "토큰이 존재하지 않습니다.") : | ||
JwtException(errorCode = 3, httpStatusCode = HttpStatus.BAD_REQUEST, message = message) | ||
JwtException(errorCode = 3, message = message) | ||
|
||
companion object { | ||
const val CODE_PREFIX = "JWT" | ||
} | ||
|
||
} | ||
} |