Skip to content

Commit

Permalink
Merge pull request #200 from GSM-MSG/199-add/exception-log
Browse files Browse the repository at this point in the history
# 199 Exception 로깅 추가
  • Loading branch information
JuuuuHong authored Jan 31, 2024
2 parents aa44def + f623500 commit aba6246
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package team.msg.hiv2.global.error

import org.slf4j.LoggerFactory
import org.springframework.http.HttpStatus
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.ExceptionHandler
Expand All @@ -9,10 +10,14 @@ import team.msg.hiv2.global.error.exception.HiException
@RestControllerAdvice
class GlobalExceptionHandler {

private val log by lazy { LoggerFactory.getLogger(this.javaClass.simpleName) }

@ExceptionHandler(HiException::class)
fun handleHiException(e: HiException): ResponseEntity<ErrorResponse> =
ResponseEntity(
ErrorResponse(e.errorCode.message, e.errorCode.status),
fun handleHiException(e: HiException): ResponseEntity<ErrorResponse> {
log.warn("Exception message = ${e.message}")
return ResponseEntity(
ErrorResponse(e.errorCode.message,e.errorCode.status),
HttpStatus.valueOf(e.errorCode.status)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ import team.msg.hiv2.global.error.exception.HiException
import javax.servlet.FilterChain
import javax.servlet.http.HttpServletRequest
import javax.servlet.http.HttpServletResponse
import org.slf4j.LoggerFactory

class ExceptionFilter: OncePerRequestFilter() {

private val log by lazy { LoggerFactory.getLogger(this.javaClass.simpleName) }

override fun doFilterInternal(
request: HttpServletRequest,
response: HttpServletResponse,
Expand All @@ -25,6 +28,10 @@ class ExceptionFilter: OncePerRequestFilter() {
is ExpiredJwtException -> exceptionToResponse(ErrorCode.EXPIRED_ACCESS_TOKEN, response)
is JwtException -> exceptionToResponse(ErrorCode.INVALID_TOKEN, response)
is HiException -> exceptionToResponse(e.errorCode, response)
else -> {
log.error(e.message)
exceptionToResponse(ErrorCode.INTERVAL_SERVER_ERROR,response)
}
}
}
}
Expand Down

0 comments on commit aba6246

Please sign in to comment.