Skip to content

Commit

Permalink
fix: fix sendCode's concurrency code.
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeqwaszx committed Jan 9, 2025
1 parent c0d8b43 commit 76b0374
Showing 1 changed file with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.*
Expand All @@ -24,17 +23,19 @@ class UserController(
@PostMapping("/signup/send-code")
fun sendCode(
@RequestBody request: SendCodeRequest,
): ResponseEntity<Void> {
CompletableFuture.runAsync {
): CompletableFuture<ResponseEntity<Void>> {
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
}
}

// 유저 이메일 인증 링크 클릭
Expand Down

0 comments on commit 76b0374

Please sign in to comment.