Skip to content

Commit

Permalink
feat: db 접속 문제 500
Browse files Browse the repository at this point in the history
  • Loading branch information
DWL21 committed Feb 13, 2025
1 parent 1d98106 commit ad73b9b
Showing 1 changed file with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package com.yourssu.soongpt.common.handler

import com.yourssu.soongpt.common.handler.dto.ErrorResponse
import io.github.oshai.kotlinlogging.KotlinLogging
import org.springframework.dao.DataAccessResourceFailureException
import org.springframework.http.HttpStatus
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.ControllerAdvice
import org.springframework.web.bind.annotation.ExceptionHandler
Expand All @@ -17,4 +19,16 @@ class InternalServerErrorControllerAdvice {
return ResponseEntity.internalServerError()
.body(ErrorResponse.from(InternalServerError()))
}

@ExceptionHandler(DataAccessResourceFailureException::class)
fun handleDataAccessException(e: DataAccessResourceFailureException): ResponseEntity<ErrorResponse> {
logger.error { e }
return ResponseEntity.status(HttpStatus.SERVICE_UNAVAILABLE)
.body(
ErrorResponse(
status = HttpStatus.SERVICE_UNAVAILABLE.value(),
message = "데이터베이스에 접근할 수 없습니다. {{ ${e.message} }}"
)
)
}
}

0 comments on commit ad73b9b

Please sign in to comment.