Skip to content

Commit 9edc7a1

Browse files
authored
release: 1.3.0 (#140)
2 parents 319fa24 + 72ead60 commit 9edc7a1

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

src/main/kotlin/org/gitanimals/core/advice/GlobalExceptionHandler.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.gitanimals.core.advice
22

3+
import org.gitanimals.core.AuthorizationException
34
import org.gitanimals.core.ErrorResponse
45
import org.slf4j.LoggerFactory
56
import 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
}

src/main/kotlin/org/gitanimals/identity/controller/advice/JwtAdvice.kt renamed to src/main/kotlin/org/gitanimals/core/advice/JwtAdvice.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
package org.gitanimals.identity.controller.advice
1+
package org.gitanimals.core.advice
22

33
import io.jsonwebtoken.ExpiredJwtException
44
import io.jsonwebtoken.JwtException
55
import io.jsonwebtoken.MalformedJwtException
66
import io.jsonwebtoken.security.SignatureException
7+
import org.gitanimals.core.ErrorResponse
78
import org.springframework.http.HttpStatus
89
import org.springframework.web.bind.annotation.ExceptionHandler
910
import org.springframework.web.bind.annotation.ResponseStatus

src/main/kotlin/org/gitanimals/identity/app/UserFacade.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.gitanimals.identity.app
22

3+
import org.gitanimals.core.AUTHORIZATION_EXCEPTION
34
import org.gitanimals.identity.domain.User
45
import org.gitanimals.identity.domain.UserService
56
import 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
}

0 commit comments

Comments
 (0)