diff --git a/build.gradle.kts b/build.gradle.kts index e806d93..090bef9 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -56,9 +56,6 @@ dependencies { // convert implementation("com.fasterxml.jackson.module:jackson-module-kotlin") - // container - developmentOnly("org.springframework.boot:spring-boot-docker-compose") - // database runtimeOnly("org.postgresql:postgresql") implementation("org.liquibase:liquibase-core") diff --git a/src/main/kotlin/com/mjucow/eatda/common/Common.kt b/src/main/kotlin/com/mjucow/eatda/common/Common.kt new file mode 100644 index 0000000..a2d9215 --- /dev/null +++ b/src/main/kotlin/com/mjucow/eatda/common/Common.kt @@ -0,0 +1,5 @@ +package com.mjucow.eatda.common + +import org.slf4j.LoggerFactory + +inline fun T.logger() = LoggerFactory.getLogger(T::class.java)!! diff --git a/src/main/kotlin/com/mjucow/eatda/presentation/common/GlobalExceptionHandler.kt b/src/main/kotlin/com/mjucow/eatda/presentation/common/GlobalExceptionHandler.kt index 5656cfc..39adaa4 100644 --- a/src/main/kotlin/com/mjucow/eatda/presentation/common/GlobalExceptionHandler.kt +++ b/src/main/kotlin/com/mjucow/eatda/presentation/common/GlobalExceptionHandler.kt @@ -1,5 +1,6 @@ package com.mjucow.eatda.presentation.common +import com.mjucow.eatda.common.logger import jakarta.persistence.EntityNotFoundException import org.springframework.http.HttpStatus import org.springframework.web.bind.annotation.ExceptionHandler @@ -7,21 +8,27 @@ import org.springframework.web.bind.annotation.ResponseStatus @GlobalControllerAdvice class GlobalExceptionHandler { + + val log = logger() + @ResponseStatus(HttpStatus.BAD_REQUEST) @ExceptionHandler(IllegalArgumentException::class) fun handleIllegalArgumentException(exception: IllegalArgumentException): ApiResponse { + log.warn(exception.message) return ApiResponse.error(exception.message) } @ResponseStatus(HttpStatus.NOT_FOUND) @ExceptionHandler(EntityNotFoundException::class) fun handleEntityNotFoundException(exception: EntityNotFoundException): ApiResponse { + log.warn(exception.message) return ApiResponse.error(exception.message) } @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) @ExceptionHandler(RuntimeException::class) fun handleRuntimeException(exception: RuntimeException): ApiResponse { + log.error(exception.stackTraceToString()) return ApiResponse.error(exception.message) } }