File tree Expand file tree Collapse file tree 3 files changed +14
-2
lines changed
src/main/kotlin/org/gitanimals Expand file tree Collapse file tree 3 files changed +14
-2
lines changed Original file line number Diff line number Diff line change 11package org.gitanimals.core.advice
22
3+ import org.gitanimals.core.AuthorizationException
34import org.gitanimals.core.ErrorResponse
45import org.slf4j.LoggerFactory
56import org.springframework.http.HttpStatus
@@ -50,4 +51,9 @@ class GlobalExceptionHandler {
5051 @ResponseStatus(HttpStatus .NOT_FOUND )
5152 fun handleNoResourceFoundException (noResourceFoundException : NoResourceFoundException ): ErrorResponse =
5253 ErrorResponse (" NOT FOUND" )
54+
55+ @ExceptionHandler(AuthorizationException ::class )
56+ @ResponseStatus(HttpStatus .UNAUTHORIZED )
57+ fun handleAuthorizationException (authorizationException : AuthorizationException ): ErrorResponse =
58+ ErrorResponse .from(authorizationException)
5359}
Original file line number Diff line number Diff line change 1- package org.gitanimals.identity.controller .advice
1+ package org.gitanimals.core .advice
22
33import io.jsonwebtoken.ExpiredJwtException
44import io.jsonwebtoken.JwtException
55import io.jsonwebtoken.MalformedJwtException
66import io.jsonwebtoken.security.SignatureException
7+ import org.gitanimals.core.ErrorResponse
78import org.springframework.http.HttpStatus
89import org.springframework.web.bind.annotation.ExceptionHandler
910import org.springframework.web.bind.annotation.ResponseStatus
Original file line number Diff line number Diff line change 11package org.gitanimals.identity.app
22
3+ import org.gitanimals.core.AUTHORIZATION_EXCEPTION
34import org.gitanimals.identity.domain.User
45import org.gitanimals.identity.domain.UserService
56import org.springframework.stereotype.Service
@@ -11,7 +12,11 @@ class UserFacade(
1112) {
1213
1314 fun getUserByToken (token : Token ): User {
14- val userId = tokenManager.getUserId(token)
15+ val userId = runCatching {
16+ tokenManager.getUserId(token)
17+ }.getOrElse {
18+ throw AUTHORIZATION_EXCEPTION
19+ }
1520
1621 return userService.getUserById(userId)
1722 }
You can’t perform that action at this time.
0 commit comments