-
Notifications
You must be signed in to change notification settings - Fork 0
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
[KS-3] Exception Handler 구현
- Loading branch information
Showing
10 changed files
with
54 additions
and
16 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
name: Katchup PR build | ||
|
||
on: | ||
push: | ||
pull_request: | ||
branches: [ "main" ] | ||
|
||
permissions: | ||
|
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 @@ | ||
# Katchup Mobile API Server |
25 changes: 25 additions & 0 deletions
25
src/main/kotlin/site/katchup/springboot/exception/GlobalControllerAdvice.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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package site.katchup.springboot.exception | ||
|
||
import org.springframework.http.ResponseEntity | ||
import org.springframework.web.bind.annotation.ExceptionHandler | ||
import org.springframework.web.bind.annotation.RestControllerAdvice | ||
import site.katchup.springboot.config.getLogger | ||
import site.katchup.springboot.exception.base.KatchupException | ||
import site.katchup.springboot.global.response.BaseResponse | ||
|
||
@RestControllerAdvice | ||
class GlobalControllerAdvice { | ||
|
||
private val log = getLogger() | ||
|
||
@ExceptionHandler(KatchupException::class) | ||
fun handleBadRequestException(exception: KatchupException): ResponseEntity<BaseResponse<Unit>> { | ||
return BaseResponse.fail(exception.httpStatus, exception.failMessage) | ||
} | ||
|
||
@ExceptionHandler(Exception::class) | ||
fun handleException(exception: Exception): ResponseEntity<BaseResponse<Unit>> { | ||
log.error(exception.message) | ||
return BaseResponse.fail(exception) | ||
} | ||
} |
5 changes: 3 additions & 2 deletions
5
src/main/kotlin/site/katchup/springboot/exception/base/BadRequestException.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,10 +1,11 @@ | ||
package site.katchup.springboot.exception.base | ||
|
||
import org.springframework.http.HttpStatus | ||
import site.katchup.springboot.global.message.FailMessage | ||
|
||
open class BadRequestException( | ||
message: String, | ||
failMessage: FailMessage, | ||
) : KatchupException( | ||
HttpStatus.BAD_REQUEST, | ||
message, | ||
failMessage, | ||
) |
5 changes: 3 additions & 2 deletions
5
src/main/kotlin/site/katchup/springboot/exception/base/ForbiddenException.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,10 +1,11 @@ | ||
package site.katchup.springboot.exception.base | ||
|
||
import org.springframework.http.HttpStatus | ||
import site.katchup.springboot.global.message.FailMessage | ||
|
||
open class ForbiddenException( | ||
message: String, | ||
failMessage: FailMessage, | ||
) : KatchupException( | ||
HttpStatus.FORBIDDEN, | ||
message, | ||
failMessage, | ||
) |
5 changes: 3 additions & 2 deletions
5
src/main/kotlin/site/katchup/springboot/exception/base/InternalServerException.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,10 +1,11 @@ | ||
package site.katchup.springboot.exception.base | ||
|
||
import org.springframework.http.HttpStatus | ||
import site.katchup.springboot.global.message.FailMessage | ||
|
||
open class InternalServerException( | ||
message: String, | ||
failMessage: FailMessage, | ||
) : KatchupException( | ||
HttpStatus.INTERNAL_SERVER_ERROR, | ||
message, | ||
failMessage, | ||
) |
7 changes: 4 additions & 3 deletions
7
src/main/kotlin/site/katchup/springboot/exception/base/KatchupException.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,8 +1,9 @@ | ||
package site.katchup.springboot.exception.base | ||
|
||
import org.springframework.http.HttpStatus | ||
import site.katchup.springboot.global.message.FailMessage | ||
|
||
open class KatchupException( | ||
httpStatus: HttpStatus, | ||
message: String, | ||
) : RuntimeException(message) | ||
val httpStatus: HttpStatus, | ||
val failMessage: FailMessage, | ||
) : RuntimeException(failMessage.value) |
5 changes: 3 additions & 2 deletions
5
src/main/kotlin/site/katchup/springboot/exception/base/NotFoundException.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,10 +1,11 @@ | ||
package site.katchup.springboot.exception.base | ||
|
||
import org.springframework.http.HttpStatus | ||
import site.katchup.springboot.global.message.FailMessage | ||
|
||
open class NotFoundException( | ||
message: String, | ||
failMessage: FailMessage, | ||
) : KatchupException( | ||
HttpStatus.NOT_FOUND, | ||
message, | ||
failMessage, | ||
) |
5 changes: 3 additions & 2 deletions
5
src/main/kotlin/site/katchup/springboot/exception/base/UnauthorizedException.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,10 +1,11 @@ | ||
package site.katchup.springboot.exception.base | ||
|
||
import org.springframework.http.HttpStatus | ||
import site.katchup.springboot.global.message.FailMessage | ||
|
||
open class UnauthorizedException( | ||
message: String, | ||
failMessage: FailMessage, | ||
) : KatchupException( | ||
HttpStatus.UNAUTHORIZED, | ||
message, | ||
failMessage, | ||
) |
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