-
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.
- Loading branch information
Showing
2 changed files
with
32 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
32 changes: 32 additions & 0 deletions
32
community-in-api/src/main/kotlin/gloddy/exception/CommunityControllerAdvice.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,32 @@ | ||
package gloddy.exception | ||
|
||
import gloddy.core.GloddyCommunityException | ||
import gloddy.response.ApiResponseEntityWrapper | ||
import gloddy.response.CommunityApiResponse | ||
import gloddy.response.fail | ||
import org.slf4j.LoggerFactory | ||
import org.springframework.http.ResponseEntity | ||
import org.springframework.web.bind.annotation.ExceptionHandler | ||
import org.springframework.web.bind.annotation.RestControllerAdvice | ||
|
||
@RestControllerAdvice(basePackages = ["gloddy"]) | ||
class CommunityControllerAdvice { | ||
|
||
companion object { | ||
private const val INTERNAL_SERVER_ERROR_CODE = 500 | ||
private const val INTERNAL_SERVER_ERROR_MESSAGE = "서버 내부 오류입니다." | ||
private val logger = LoggerFactory.getLogger(CommunityControllerAdvice::class.java) | ||
} | ||
|
||
@ExceptionHandler(GloddyCommunityException::class) | ||
fun handleGloddyCummunityException(e: GloddyCommunityException): ResponseEntity<CommunityApiResponse<Nothing>> { | ||
logger.error("Community Error\n{}", e.message, e) | ||
return ApiResponseEntityWrapper<Nothing>().fail(e.statusCode, e.message) | ||
} | ||
|
||
@ExceptionHandler(Exception::class) | ||
fun handleInternalServerError(e: Exception): ResponseEntity<CommunityApiResponse<Nothing>> { | ||
logger.error("Community Internal Error\n{}", e.message, e) | ||
return ApiResponseEntityWrapper<Nothing>().fail(INTERNAL_SERVER_ERROR_CODE, INTERNAL_SERVER_ERROR_MESSAGE) | ||
} | ||
} |