Skip to content

Commit

Permalink
feat: CommunityControllerAdvice 작성
Browse files Browse the repository at this point in the history
  • Loading branch information
jihwan2da committed Jan 8, 2024
1 parent 7e549e9 commit b020bf7
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
Empty file.
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)
}
}

0 comments on commit b020bf7

Please sign in to comment.