Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[etc] logger 추가 및 Exception logging 추가 #71

Merged
merged 2 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
5 changes: 5 additions & 0 deletions src/main/kotlin/com/mjucow/eatda/common/Common.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.mjucow.eatda.common

import org.slf4j.LoggerFactory

inline fun <reified T> T.logger() = LoggerFactory.getLogger(T::class.java)!!
Original file line number Diff line number Diff line change
@@ -1,27 +1,34 @@
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
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<Unit> {
log.warn(exception.message)

Check warning on line 17 in src/main/kotlin/com/mjucow/eatda/presentation/common/GlobalExceptionHandler.kt

View check run for this annotation

Codecov / codecov/patch

src/main/kotlin/com/mjucow/eatda/presentation/common/GlobalExceptionHandler.kt#L17

Added line #L17 was not covered by tests
return ApiResponse.error(exception.message)
}

@ResponseStatus(HttpStatus.NOT_FOUND)
@ExceptionHandler(EntityNotFoundException::class)
fun handleEntityNotFoundException(exception: EntityNotFoundException): ApiResponse<Unit> {
log.warn(exception.message)

Check warning on line 24 in src/main/kotlin/com/mjucow/eatda/presentation/common/GlobalExceptionHandler.kt

View check run for this annotation

Codecov / codecov/patch

src/main/kotlin/com/mjucow/eatda/presentation/common/GlobalExceptionHandler.kt#L24

Added line #L24 was not covered by tests
return ApiResponse.error(exception.message)
}

@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
@ExceptionHandler(RuntimeException::class)
fun handleRuntimeException(exception: RuntimeException): ApiResponse<Unit> {
log.error(exception.stackTraceToString())

Check warning on line 31 in src/main/kotlin/com/mjucow/eatda/presentation/common/GlobalExceptionHandler.kt

View check run for this annotation

Codecov / codecov/patch

src/main/kotlin/com/mjucow/eatda/presentation/common/GlobalExceptionHandler.kt#L31

Added line #L31 was not covered by tests
return ApiResponse.error(exception.message)
}
}