From 8ac5c5e1c52e36c4725977296150184a6f2024bd Mon Sep 17 00:00:00 2001 From: Gemini Kim Date: Tue, 17 Sep 2024 14:36:52 +0900 Subject: [PATCH] Repackaged errors and responses for the core. --- .../core/api/config/AsyncExceptionHandler.kt | 10 +++++----- .../core/api/controller/ApiControllerAdvice.kt | 16 ++++++++-------- .../core/api/controller/v1/ExampleController.kt | 2 +- .../core/api/support/error/ErrorCode.kt | 5 ----- .../core/api/support/response/ResultType.kt | 6 ------ .../error/CoreException.kt} | 4 ++-- .../springboot/core/support/error/ErrorCode.kt | 5 +++++ .../core/{api => }/support/error/ErrorMessage.kt | 2 +- .../core/{api => }/support/error/ErrorType.kt | 2 +- .../{api => }/support/response/ApiResponse.kt | 6 +++--- .../core/support/response/ResultType.kt | 6 ++++++ 11 files changed, 32 insertions(+), 32 deletions(-) delete mode 100644 core/core-api/src/main/kotlin/io/dodn/springboot/core/api/support/error/ErrorCode.kt delete mode 100644 core/core-api/src/main/kotlin/io/dodn/springboot/core/api/support/response/ResultType.kt rename core/core-api/src/main/kotlin/io/dodn/springboot/core/{api/support/error/CoreApiException.kt => support/error/CoreException.kt} (56%) create mode 100644 core/core-api/src/main/kotlin/io/dodn/springboot/core/support/error/ErrorCode.kt rename core/core-api/src/main/kotlin/io/dodn/springboot/core/{api => }/support/error/ErrorMessage.kt (85%) rename core/core-api/src/main/kotlin/io/dodn/springboot/core/{api => }/support/error/ErrorType.kt (86%) rename core/core-api/src/main/kotlin/io/dodn/springboot/core/{api => }/support/response/ApiResponse.kt (77%) create mode 100644 core/core-api/src/main/kotlin/io/dodn/springboot/core/support/response/ResultType.kt diff --git a/core/core-api/src/main/kotlin/io/dodn/springboot/core/api/config/AsyncExceptionHandler.kt b/core/core-api/src/main/kotlin/io/dodn/springboot/core/api/config/AsyncExceptionHandler.kt index 0fe1905..4fbb77f 100644 --- a/core/core-api/src/main/kotlin/io/dodn/springboot/core/api/config/AsyncExceptionHandler.kt +++ b/core/core-api/src/main/kotlin/io/dodn/springboot/core/api/config/AsyncExceptionHandler.kt @@ -1,6 +1,6 @@ package io.dodn.springboot.core.api.config -import io.dodn.springboot.core.api.support.error.CoreApiException +import io.dodn.springboot.core.support.error.CoreException import org.slf4j.LoggerFactory import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler import org.springframework.boot.logging.LogLevel @@ -10,11 +10,11 @@ class AsyncExceptionHandler : AsyncUncaughtExceptionHandler { private val log = LoggerFactory.getLogger(javaClass) override fun handleUncaughtException(e: Throwable, method: Method, vararg params: Any?) { - if (e is CoreApiException) { + if (e is CoreException) { when (e.errorType.logLevel) { - LogLevel.ERROR -> log.error("CoreApiException : {}", e.message, e) - LogLevel.WARN -> log.warn("CoreApiException : {}", e.message, e) - else -> log.info("CoreApiException : {}", e.message, e) + LogLevel.ERROR -> log.error("CoreException : {}", e.message, e) + LogLevel.WARN -> log.warn("CoreException : {}", e.message, e) + else -> log.info("CoreException : {}", e.message, e) } } else { log.error("Exception : {}", e.message, e) diff --git a/core/core-api/src/main/kotlin/io/dodn/springboot/core/api/controller/ApiControllerAdvice.kt b/core/core-api/src/main/kotlin/io/dodn/springboot/core/api/controller/ApiControllerAdvice.kt index 946f497..e3f9c9a 100644 --- a/core/core-api/src/main/kotlin/io/dodn/springboot/core/api/controller/ApiControllerAdvice.kt +++ b/core/core-api/src/main/kotlin/io/dodn/springboot/core/api/controller/ApiControllerAdvice.kt @@ -1,8 +1,8 @@ package io.dodn.springboot.core.api.controller -import io.dodn.springboot.core.api.support.error.CoreApiException -import io.dodn.springboot.core.api.support.error.ErrorType -import io.dodn.springboot.core.api.support.response.ApiResponse +import io.dodn.springboot.core.support.error.CoreException +import io.dodn.springboot.core.support.error.ErrorType +import io.dodn.springboot.core.support.response.ApiResponse import org.slf4j.Logger import org.slf4j.LoggerFactory import org.springframework.boot.logging.LogLevel @@ -14,12 +14,12 @@ import org.springframework.web.bind.annotation.RestControllerAdvice class ApiControllerAdvice { private val log: Logger = LoggerFactory.getLogger(javaClass) - @ExceptionHandler(CoreApiException::class) - fun handleCoreApiException(e: CoreApiException): ResponseEntity> { + @ExceptionHandler(CoreException::class) + fun handleCoreException(e: CoreException): ResponseEntity> { when (e.errorType.logLevel) { - LogLevel.ERROR -> log.error("CoreApiException : {}", e.message, e) - LogLevel.WARN -> log.warn("CoreApiException : {}", e.message, e) - else -> log.info("CoreApiException : {}", e.message, e) + LogLevel.ERROR -> log.error("CoreException : {}", e.message, e) + LogLevel.WARN -> log.warn("CoreException : {}", e.message, e) + else -> log.info("CoreException : {}", e.message, e) } return ResponseEntity(ApiResponse.error(e.errorType, e.data), e.errorType.status) } diff --git a/core/core-api/src/main/kotlin/io/dodn/springboot/core/api/controller/v1/ExampleController.kt b/core/core-api/src/main/kotlin/io/dodn/springboot/core/api/controller/v1/ExampleController.kt index e40ba90..8913a4d 100644 --- a/core/core-api/src/main/kotlin/io/dodn/springboot/core/api/controller/v1/ExampleController.kt +++ b/core/core-api/src/main/kotlin/io/dodn/springboot/core/api/controller/v1/ExampleController.kt @@ -2,9 +2,9 @@ package io.dodn.springboot.core.api.controller.v1 import io.dodn.springboot.core.api.controller.v1.request.ExampleRequestDto import io.dodn.springboot.core.api.controller.v1.response.ExampleResponseDto -import io.dodn.springboot.core.api.support.response.ApiResponse import io.dodn.springboot.core.domain.ExampleData import io.dodn.springboot.core.domain.ExampleService +import io.dodn.springboot.core.support.response.ApiResponse import org.springframework.web.bind.annotation.GetMapping import org.springframework.web.bind.annotation.PathVariable import org.springframework.web.bind.annotation.PostMapping diff --git a/core/core-api/src/main/kotlin/io/dodn/springboot/core/api/support/error/ErrorCode.kt b/core/core-api/src/main/kotlin/io/dodn/springboot/core/api/support/error/ErrorCode.kt deleted file mode 100644 index 90b5166..0000000 --- a/core/core-api/src/main/kotlin/io/dodn/springboot/core/api/support/error/ErrorCode.kt +++ /dev/null @@ -1,5 +0,0 @@ -package io.dodn.springboot.core.api.support.error - -enum class ErrorCode { - E500, -} diff --git a/core/core-api/src/main/kotlin/io/dodn/springboot/core/api/support/response/ResultType.kt b/core/core-api/src/main/kotlin/io/dodn/springboot/core/api/support/response/ResultType.kt deleted file mode 100644 index 23b7a7d..0000000 --- a/core/core-api/src/main/kotlin/io/dodn/springboot/core/api/support/response/ResultType.kt +++ /dev/null @@ -1,6 +0,0 @@ -package io.dodn.springboot.core.api.support.response - -enum class ResultType { - SUCCESS, - ERROR, -} diff --git a/core/core-api/src/main/kotlin/io/dodn/springboot/core/api/support/error/CoreApiException.kt b/core/core-api/src/main/kotlin/io/dodn/springboot/core/support/error/CoreException.kt similarity index 56% rename from core/core-api/src/main/kotlin/io/dodn/springboot/core/api/support/error/CoreApiException.kt rename to core/core-api/src/main/kotlin/io/dodn/springboot/core/support/error/CoreException.kt index 6815b19..859feab 100644 --- a/core/core-api/src/main/kotlin/io/dodn/springboot/core/api/support/error/CoreApiException.kt +++ b/core/core-api/src/main/kotlin/io/dodn/springboot/core/support/error/CoreException.kt @@ -1,6 +1,6 @@ -package io.dodn.springboot.core.api.support.error +package io.dodn.springboot.core.support.error -class CoreApiException( +class CoreException( val errorType: ErrorType, val data: Any? = null, ) : RuntimeException(errorType.message) diff --git a/core/core-api/src/main/kotlin/io/dodn/springboot/core/support/error/ErrorCode.kt b/core/core-api/src/main/kotlin/io/dodn/springboot/core/support/error/ErrorCode.kt new file mode 100644 index 0000000..683dd5f --- /dev/null +++ b/core/core-api/src/main/kotlin/io/dodn/springboot/core/support/error/ErrorCode.kt @@ -0,0 +1,5 @@ +package io.dodn.springboot.core.support.error + +enum class ErrorCode { + E500, +} diff --git a/core/core-api/src/main/kotlin/io/dodn/springboot/core/api/support/error/ErrorMessage.kt b/core/core-api/src/main/kotlin/io/dodn/springboot/core/support/error/ErrorMessage.kt similarity index 85% rename from core/core-api/src/main/kotlin/io/dodn/springboot/core/api/support/error/ErrorMessage.kt rename to core/core-api/src/main/kotlin/io/dodn/springboot/core/support/error/ErrorMessage.kt index 656b5de..f39acea 100644 --- a/core/core-api/src/main/kotlin/io/dodn/springboot/core/api/support/error/ErrorMessage.kt +++ b/core/core-api/src/main/kotlin/io/dodn/springboot/core/support/error/ErrorMessage.kt @@ -1,4 +1,4 @@ -package io.dodn.springboot.core.api.support.error +package io.dodn.springboot.core.support.error data class ErrorMessage private constructor( val code: String, diff --git a/core/core-api/src/main/kotlin/io/dodn/springboot/core/api/support/error/ErrorType.kt b/core/core-api/src/main/kotlin/io/dodn/springboot/core/support/error/ErrorType.kt similarity index 86% rename from core/core-api/src/main/kotlin/io/dodn/springboot/core/api/support/error/ErrorType.kt rename to core/core-api/src/main/kotlin/io/dodn/springboot/core/support/error/ErrorType.kt index 2fc96e2..3a9f77e 100644 --- a/core/core-api/src/main/kotlin/io/dodn/springboot/core/api/support/error/ErrorType.kt +++ b/core/core-api/src/main/kotlin/io/dodn/springboot/core/support/error/ErrorType.kt @@ -1,4 +1,4 @@ -package io.dodn.springboot.core.api.support.error +package io.dodn.springboot.core.support.error import org.springframework.boot.logging.LogLevel import org.springframework.http.HttpStatus diff --git a/core/core-api/src/main/kotlin/io/dodn/springboot/core/api/support/response/ApiResponse.kt b/core/core-api/src/main/kotlin/io/dodn/springboot/core/support/response/ApiResponse.kt similarity index 77% rename from core/core-api/src/main/kotlin/io/dodn/springboot/core/api/support/response/ApiResponse.kt rename to core/core-api/src/main/kotlin/io/dodn/springboot/core/support/response/ApiResponse.kt index 821dfd0..5cba253 100644 --- a/core/core-api/src/main/kotlin/io/dodn/springboot/core/api/support/response/ApiResponse.kt +++ b/core/core-api/src/main/kotlin/io/dodn/springboot/core/support/response/ApiResponse.kt @@ -1,7 +1,7 @@ -package io.dodn.springboot.core.api.support.response +package io.dodn.springboot.core.support.response -import io.dodn.springboot.core.api.support.error.ErrorMessage -import io.dodn.springboot.core.api.support.error.ErrorType +import io.dodn.springboot.core.support.error.ErrorMessage +import io.dodn.springboot.core.support.error.ErrorType data class ApiResponse private constructor( val result: ResultType, diff --git a/core/core-api/src/main/kotlin/io/dodn/springboot/core/support/response/ResultType.kt b/core/core-api/src/main/kotlin/io/dodn/springboot/core/support/response/ResultType.kt new file mode 100644 index 0000000..8fa2375 --- /dev/null +++ b/core/core-api/src/main/kotlin/io/dodn/springboot/core/support/response/ResultType.kt @@ -0,0 +1,6 @@ +package io.dodn.springboot.core.support.response + +enum class ResultType { + SUCCESS, + ERROR, +}