Skip to content

Commit

Permalink
refactor: 인증 실패시 403예외를 던지도록 수정한다
Browse files Browse the repository at this point in the history
  • Loading branch information
devxb committed May 17, 2024
1 parent 17b164e commit 5276fc5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/main/kotlin/org/gitanimals/render/app/Exception.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.gitanimals.render.app


class AuthorizationException(message: String) : IllegalArgumentException(message)

val AUTHORIZATION_EXCEPTION = AuthorizationException("Authorization fail")
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.gitanimals.render.controller

import org.gitanimals.render.app.AuthorizationException
import org.gitanimals.render.app.UserFacade
import org.gitanimals.render.controller.request.AddPersonaRequest
import org.gitanimals.render.controller.response.ErrorResponse
Expand Down Expand Up @@ -79,4 +80,9 @@ class PersonaController(
@ResponseStatus(HttpStatus.BAD_REQUEST)
fun handleIllegalArgumentException(exception: IllegalArgumentException): ErrorResponse =
ErrorResponse.from(exception)

@ExceptionHandler(AuthorizationException::class)
@ResponseStatus(HttpStatus.UNAUTHORIZED)
fun handleAuthorizationException(exception: AuthorizationException): ErrorResponse =
ErrorResponse.from(exception)
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.gitanimals.render.infra

import org.gitanimals.render.app.AUTHORIZATION_EXCEPTION
import org.gitanimals.render.app.IdentityApi
import org.springframework.http.HttpHeaders
import org.springframework.stereotype.Component
Expand All @@ -18,7 +19,7 @@ class RestIdentityApi : IdentityApi {
runCatching {
response.bodyTo(IdentityApi.UserResponse::class.java)
}.getOrElse {
throw IllegalArgumentException("Unauthorized user")
throw AUTHORIZATION_EXCEPTION
}
}
}
Expand Down

0 comments on commit 5276fc5

Please sign in to comment.