Skip to content

Commit

Permalink
feat: ErrorType이 LogLevel을 들고 있을 수 있도록 수정, ControllerAdvice에서 이를 사용하여 로깅
Browse files Browse the repository at this point in the history
  • Loading branch information
Dompoo committed Jul 25, 2024
1 parent c413c08 commit cc81fb5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package dnd11th.blooming.common.exception

import org.springframework.boot.logging.LogLevel
import org.springframework.http.HttpStatus

enum class ErrorType(val status: HttpStatus, val message: String) {
INVALID_DATE(HttpStatus.BAD_REQUEST, "올바르지 않은 날짜입니다."),
NOT_FOUND_PLANT_ID(HttpStatus.NOT_FOUND, "존재하지 않는 식물입니다."),
enum class ErrorType(val status: HttpStatus, val message: String, val logLevel: LogLevel) {
INVALID_DATE(HttpStatus.BAD_REQUEST, "올바르지 않은 날짜입니다.", LogLevel.DEBUG),
NOT_FOUND_PLANT_ID(HttpStatus.NOT_FOUND, "존재하지 않는 식물입니다.", LogLevel.DEBUG),
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dnd11th.blooming.common.exception

import org.springframework.boot.logging.LogLevel
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.ExceptionHandler
import org.springframework.web.bind.annotation.RestControllerAdvice
Expand All @@ -9,6 +10,11 @@ class GlobalExceptionHandler {
@ExceptionHandler(MyException::class)
fun handleMyException(exception: MyException): ResponseEntity<ErrorResponse> {
val errorType = exception.errorType
when (errorType.logLevel) {
LogLevel.ERROR -> {}
LogLevel.WARN -> {}
else -> {}
}
return ResponseEntity
.status(errorType.status)
.body(ErrorResponse.from(errorType))
Expand Down

0 comments on commit cc81fb5

Please sign in to comment.