diff --git a/bootstrap/src/test/kotlin/gloddy/.gitkeep b/bootstrap/src/test/kotlin/gloddy/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/community-in-api/src/main/kotlin/gloddy/exception/CommunityControllerAdvice.kt b/community-in-api/src/main/kotlin/gloddy/exception/CommunityControllerAdvice.kt new file mode 100644 index 0000000..df8923e --- /dev/null +++ b/community-in-api/src/main/kotlin/gloddy/exception/CommunityControllerAdvice.kt @@ -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> { + logger.error("Community Error\n{}", e.message, e) + return ApiResponseEntityWrapper().fail(e.statusCode, e.message) + } + + @ExceptionHandler(Exception::class) + fun handleInternalServerError(e: Exception): ResponseEntity> { + logger.error("Community Internal Error\n{}", e.message, e) + return ApiResponseEntityWrapper().fail(INTERNAL_SERVER_ERROR_CODE, INTERNAL_SERVER_ERROR_MESSAGE) + } +} \ No newline at end of file