From 76b03745d58c6d387c42126f7ac6196e6f6fd07c Mon Sep 17 00:00:00 2001 From: Jonghyun Lee Date: Fri, 10 Jan 2025 04:57:49 +0900 Subject: [PATCH] fix: fix sendCode's concurrency code. --- .../account/controller/UserController.kt | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/main/kotlin/com/waffletoy/team1server/account/controller/UserController.kt b/src/main/kotlin/com/waffletoy/team1server/account/controller/UserController.kt index bb255dd..8735290 100644 --- a/src/main/kotlin/com/waffletoy/team1server/account/controller/UserController.kt +++ b/src/main/kotlin/com/waffletoy/team1server/account/controller/UserController.kt @@ -8,7 +8,6 @@ import com.waffletoy.team1server.account.service.UserService import io.swagger.v3.oas.annotations.Parameter import jakarta.servlet.http.HttpServletResponse import org.springframework.beans.factory.annotation.Value -import org.springframework.http.HttpStatus import org.springframework.http.ResponseCookie import org.springframework.http.ResponseEntity import org.springframework.web.bind.annotation.* @@ -24,17 +23,19 @@ class UserController( @PostMapping("/signup/send-code") fun sendCode( @RequestBody request: SendCodeRequest, - ): ResponseEntity { - CompletableFuture.runAsync { + ): CompletableFuture> { + return CompletableFuture.runAsync { emailService.sendCode(request.snuMail) - }.exceptionally { - throw EmailServiceException( - "동일한 스누메일로 등록된 계정이 존재합니다.", - HttpStatus.CONFLICT, - ) - }.join() - - return ResponseEntity.ok().build() + }.handle { _, ex -> + if (ex != null) { + val cause = ex.cause ?: ex + if (cause is EmailServiceException) { + throw cause // Propagate the original EmailServiceException + } + throw RuntimeException("Unexpected error occurred", cause) // Wrap other exceptions + } + ResponseEntity.ok().build() // Return the successful response + } } // 유저 이메일 인증 링크 클릭