From b020bf72e9f289510e071aecc40cb64d9326958b Mon Sep 17 00:00:00 2001 From: jihwan2da Date: Tue, 9 Jan 2024 02:53:49 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20CommunityControllerAdvice=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bootstrap/src/test/kotlin/gloddy/.gitkeep | 0 .../exception/CommunityControllerAdvice.kt | 32 +++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 bootstrap/src/test/kotlin/gloddy/.gitkeep create mode 100644 community-in-api/src/main/kotlin/gloddy/exception/CommunityControllerAdvice.kt 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