Skip to content

Commit

Permalink
feat: kotlin - log 추가 및 예외 에러 로그 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
YongsHub committed Mar 28, 2024
1 parent 9456b7f commit 2c4f0fb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 3 additions & 0 deletions lovebird-api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ dependencies {
testImplementation("io.kotest:kotest-assertions-core:${property("kotestVersion")}")
testImplementation("io.kotest.extensions:kotest-extensions-spring:${property("kotestSpringVersion")}")
testImplementation("com.ninja-squad:springmockk:4.0.2")

// kotlin -log
implementation("io.github.oshai:kotlin-logging-jvm:5.1.1")
}

tasks.asciidoctor {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.lovebird.api.service.slack.SlackService
import com.lovebird.common.enums.ReturnCode
import com.lovebird.common.exception.LbException
import com.lovebird.common.response.ApiResponse
import io.github.oshai.kotlinlogging.KotlinLogging
import jakarta.servlet.http.HttpServletRequest
import org.springframework.http.HttpStatus
import org.springframework.http.ResponseEntity
Expand All @@ -22,9 +23,12 @@ import java.sql.SQLException
class GlobalControllerAdvice(
private val slackService: SlackService
) {
private val logger = KotlinLogging.logger {}

@ExceptionHandler(LbException::class)
fun handleLbException(e: LbException): ResponseEntity<ApiResponse<Unit>> {
logger.error { e.getMsg() }

return ResponseEntity
.status(HttpStatus.BAD_REQUEST)
.body(ApiResponse.fail(e.getReturnCode()))
Expand Down Expand Up @@ -78,7 +82,6 @@ class GlobalControllerAdvice(
)
fun handleBusinessException(e: RuntimeException, request: HttpServletRequest): ResponseEntity<ApiResponse<Unit>> {
slackService.sendSlackForError(e, request)

return ResponseEntity
.status(HttpStatus.INTERNAL_SERVER_ERROR)
.body(ApiResponse.error(ReturnCode.INTERNAL_SERVER_ERROR))
Expand Down

0 comments on commit 2c4f0fb

Please sign in to comment.