Skip to content

Commit

Permalink
Hotfix | #81 | @YongsHub | v1.0.1 JWT 예외 상황 분리
Browse files Browse the repository at this point in the history
* feature: JWT Token 예외 상황 분리

* feat: kotlin - log 추가 및 예외 에러 로그 추가

* chore: open source kotlin-log 제거
  • Loading branch information
YongsHub authored Mar 28, 2024
1 parent 9a650ed commit bdae46f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.lovebird.common.enums.ReturnCode
import com.lovebird.common.exception.LbException
import com.lovebird.common.response.ApiResponse
import jakarta.servlet.http.HttpServletRequest
import org.slf4j.LoggerFactory
import org.springframework.http.HttpStatus
import org.springframework.http.ResponseEntity
import org.springframework.http.converter.HttpMessageNotReadableException
Expand All @@ -22,9 +23,12 @@ import java.sql.SQLException
class GlobalControllerAdvice(
private val slackService: SlackService
) {
private val logger = LoggerFactory.getLogger(javaClass)

@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
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.lovebird.common.exception.LbException
import com.lovebird.domain.entity.User
import com.lovebird.domain.repository.reader.UserReader
import io.jsonwebtoken.Claims
import io.jsonwebtoken.ExpiredJwtException
import io.jsonwebtoken.Jwts
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken
import org.springframework.security.core.Authentication
Expand Down Expand Up @@ -57,8 +58,9 @@ class JwtValidator(
.build()
.parseClaimsJws(token)
.body
} catch (e: ExpiredJwtException) {
throw LbException(ReturnCode.EXPIRED_JWT_TOKEN)
} catch (e: RuntimeException) {
println(e.message)
throw LbException(ReturnCode.WRONG_JWT_TOKEN)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ enum class ReturnCode(val code: String, val message: String) {
// 토큰 관련
NOT_EXIST_BEARER_SUFFIX("1100", "Bearer 접두사가 포함되지 않았습니다."),
WRONG_JWT_TOKEN("1101", "잘못된 jwt 토큰입니다."),
EXPIRED_JWT_TOKEN("1102", "만료된 jwt 토큰입니다"),

// 유저 관련
WRONG_PROVIDER("1200", "잘못된 인증 제공자 입니다."),
Expand Down

0 comments on commit bdae46f

Please sign in to comment.