From 17b164e2499f42af64342c24c42d1447ebcec857 Mon Sep 17 00:00:00 2001 From: devxb Date: Fri, 17 May 2024 23:14:36 +0900 Subject: [PATCH 1/2] =?UTF-8?q?refactor:=20=EB=A9=94=EC=9D=B8=EC=BA=90?= =?UTF-8?q?=EB=A6=AD=ED=84=B0=EB=A5=BC=20LITTLE=5FCHICK=5FSPRING=EC=9C=BC?= =?UTF-8?q?=EB=A1=9C=20=EB=B3=80=EA=B2=BD=ED=95=9C=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ENGLISH.md | 2 +- README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ENGLISH.md b/ENGLISH.md index d62184f..20f1401 100644 --- a/ENGLISH.md +++ b/ENGLISH.md @@ -9,7 +9,7 @@
- + ⭐️ Please press the star! It greatly helps development! ⭐️
diff --git a/README.md b/README.md index 74fcb0b..a2b99cd 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@
- + ⭐스타를 눌러주세요 개발에 큰 도움이 됩니다!⭐️
From 5276fc57c7440608a9910788ddada44384fd2129 Mon Sep 17 00:00:00 2001 From: devxb Date: Sat, 18 May 2024 01:30:29 +0900 Subject: [PATCH 2/2] =?UTF-8?q?refactor:=20=EC=9D=B8=EC=A6=9D=20=EC=8B=A4?= =?UTF-8?q?=ED=8C=A8=EC=8B=9C=20403=EC=98=88=EC=99=B8=EB=A5=BC=20=EB=8D=98?= =?UTF-8?q?=EC=A7=80=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95=ED=95=9C?= =?UTF-8?q?=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/org/gitanimals/render/app/Exception.kt | 6 ++++++ .../org/gitanimals/render/controller/PersonaController.kt | 6 ++++++ .../kotlin/org/gitanimals/render/infra/RestIdentityApi.kt | 3 ++- 3 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 src/main/kotlin/org/gitanimals/render/app/Exception.kt diff --git a/src/main/kotlin/org/gitanimals/render/app/Exception.kt b/src/main/kotlin/org/gitanimals/render/app/Exception.kt new file mode 100644 index 0000000..d0eae82 --- /dev/null +++ b/src/main/kotlin/org/gitanimals/render/app/Exception.kt @@ -0,0 +1,6 @@ +package org.gitanimals.render.app + + +class AuthorizationException(message: String) : IllegalArgumentException(message) + +val AUTHORIZATION_EXCEPTION = AuthorizationException("Authorization fail") diff --git a/src/main/kotlin/org/gitanimals/render/controller/PersonaController.kt b/src/main/kotlin/org/gitanimals/render/controller/PersonaController.kt index 41a9c30..5a24e7b 100644 --- a/src/main/kotlin/org/gitanimals/render/controller/PersonaController.kt +++ b/src/main/kotlin/org/gitanimals/render/controller/PersonaController.kt @@ -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 @@ -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) } diff --git a/src/main/kotlin/org/gitanimals/render/infra/RestIdentityApi.kt b/src/main/kotlin/org/gitanimals/render/infra/RestIdentityApi.kt index 9b394c5..6ee94a9 100644 --- a/src/main/kotlin/org/gitanimals/render/infra/RestIdentityApi.kt +++ b/src/main/kotlin/org/gitanimals/render/infra/RestIdentityApi.kt @@ -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 @@ -18,7 +19,7 @@ class RestIdentityApi : IdentityApi { runCatching { response.bodyTo(IdentityApi.UserResponse::class.java) }.getOrElse { - throw IllegalArgumentException("Unauthorized user") + throw AUTHORIZATION_EXCEPTION } } }