Skip to content

Commit

Permalink
🐛fix : thread starvation 에러수정
Browse files Browse the repository at this point in the history
 - thread pool size 조정
 - stdout log 최소화
 - Exception 핸들러 추가설정
  • Loading branch information
ParkYunHo committed Apr 21, 2024
1 parent 4cd9654 commit ef6fa3c
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ class AuthController(
*/
@GetMapping("/auth/token")
fun token(@Validated input: TokenRequest): CommonResponse<TokenResponse> {
log.info("[token] input: $input")

val result = generateTokenUseCase.reIssueToken(input.token)
return CommonResponse.success(data = TokenResponse.of(input = result))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import org.springframework.core.Ordered
import org.springframework.core.annotation.Order
import org.springframework.http.HttpHeaders
import org.springframework.stereotype.Component
import org.springframework.util.StringUtils
import org.springframework.web.context.request.RequestContextHolder
import org.springframework.web.context.request.ServletRequestAttributes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ enum class ResponseCode(
SUCCESS("0", "Success"),
BAD_REQUEST("400", "Bad Request"),
UNAUTHORIZED("401", "Invalid Token"),
SERVER_ERROR("500", "Internal Server Error"),

COUPLE_CODE_NOT_FOUND("T001", "Couple Code Not Found"),
DATA_NOT_FOUND("T002", "Data Not Found"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.ddd.teople.bootstrap.global.common.exception.AuthenticationException
import org.slf4j.LoggerFactory
import org.springframework.http.HttpStatus
import org.springframework.validation.BindException
import org.springframework.web.bind.MethodArgumentNotValidException
import org.springframework.web.bind.annotation.ExceptionHandler
import org.springframework.web.bind.annotation.ResponseBody
import org.springframework.web.bind.annotation.ResponseStatus
Expand All @@ -21,50 +22,80 @@ class CommonExceptionHandler {
@ExceptionHandler(BindException::class)
@ResponseStatus(value = HttpStatus.BAD_REQUEST)
@ResponseBody
fun bindException(e: BindException): CommonResponse<Nothing> =
fun handleBindException(e: BindException): CommonResponse<Nothing> =
CommonResponse(
code = ResponseCode.BAD_REQUEST.code,
message = ResponseCode.BAD_REQUEST.message,
data = null
).also { log.error("[BindException] Exception occurs - message: {}", e.message, e) }
).also { log.error("[BindException] Exception occurs - message: {}", e.message) }

@ExceptionHandler(MethodArgumentNotValidException::class)
@ResponseStatus(value = HttpStatus.BAD_REQUEST)
@ResponseBody
fun handleMethodArgumentNotValidException(e: MethodArgumentNotValidException): CommonResponse<Nothing> =
CommonResponse(
code = ResponseCode.BAD_REQUEST.code,
message = ResponseCode.BAD_REQUEST.message,
data = null
).also { log.error("[MethodArgumentNotValidException] Exception occurs - message: {}", e.message) }

@ExceptionHandler(JwtInvalidException::class)
@ResponseStatus(value = HttpStatus.UNAUTHORIZED)
@ResponseBody
fun jwtInvalidException(e: JwtInvalidException): CommonResponse<Nothing> =
fun handleJwtInvalidException(e: JwtInvalidException): CommonResponse<Nothing> =
CommonResponse(
code = ResponseCode.UNAUTHORIZED.code,
message = if(e.message.isNullOrEmpty()) ResponseCode.UNAUTHORIZED.message else e.message!!,
message = ResponseCode.UNAUTHORIZED.message,
data = null
).also { log.error("[JwtInvalidException] Exception occurs - message: {}", e.message, e) }
).also { log.error("[JwtInvalidException] Exception occurs - message: {}", e.message) }

@ExceptionHandler(AuthenticationException::class)
@ResponseStatus(value = HttpStatus.UNAUTHORIZED)
@ResponseBody
fun authenticationException(e: AuthenticationException): CommonResponse<Nothing> =
fun handleAuthenticationException(e: AuthenticationException): CommonResponse<Nothing> =
CommonResponse(
code = ResponseCode.UNAUTHORIZED.code,
message = if(e.message.isNullOrEmpty()) ResponseCode.UNAUTHORIZED.message else e.message!!,
message = ResponseCode.UNAUTHORIZED.message,
data = null
).also { log.error("[AuthenticationException] Exception occurs - message: {}", e.message, e) }
).also { log.error("[AuthenticationException] Exception occurs - message: {}", e.message) }

@ExceptionHandler(CoupleCodeInvalidException::class)
@ResponseStatus(value = HttpStatus.BAD_REQUEST)
@ResponseBody
fun coupleCodeInvalidException(e: CoupleCodeInvalidException): CommonResponse<Nothing> =
fun handleCoupleCodeInvalidException(e: CoupleCodeInvalidException): CommonResponse<Nothing> =
CommonResponse(
code = ResponseCode.COUPLE_CODE_NOT_FOUND.code,
message = if(e.message.isNullOrEmpty()) ResponseCode.COUPLE_CODE_NOT_FOUND.message else e.message!!,
message = ResponseCode.COUPLE_CODE_NOT_FOUND.code,
data = null
).also { log.error("[CoupleCodeInvalidException] Exception occurs - message: {}", e.message, e) }
).also { log.error("[CoupleCodeInvalidException] Exception occurs - message: {}", e.message) }

@ExceptionHandler(DataNotFoundException::class)
@ResponseStatus(value = HttpStatus.BAD_REQUEST)
@ResponseBody
fun dataNotFoundException(e: DataNotFoundException): CommonResponse<Nothing> =
fun handleDataNotFoundException(e: DataNotFoundException): CommonResponse<Nothing> =
CommonResponse(
code = ResponseCode.DATA_NOT_FOUND.code,
message = if(e.message.isNullOrEmpty()) ResponseCode.DATA_NOT_FOUND.message else e.message!!,
message = ResponseCode.DATA_NOT_FOUND.code,
data = null
).also { log.error("[DataNotFoundException] Exception occurs - message: {}", e.message) }

@ExceptionHandler(IllegalArgumentException::class)
@ResponseStatus(value = HttpStatus.BAD_REQUEST)
@ResponseBody
fun handleIllegalArgumentException(e: IllegalArgumentException): CommonResponse<Nothing> =
CommonResponse(
code = ResponseCode.BAD_REQUEST.code,
message = ResponseCode.BAD_REQUEST.code,
data = null
).also { log.error("[IllegalArgumentException] Exception occurs - message: {}", e.message) }

@ExceptionHandler(Exception::class)
@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
@ResponseBody
fun handleException(e: Exception): CommonResponse<Nothing> =
CommonResponse(
code = ResponseCode.SERVER_ERROR.code,
message = ResponseCode.SERVER_ERROR.code,
data = null
).also { log.error("[DataNotFoundException] Exception occurs - message: {}", e.message, e) }
).also { log.error("[Exception] Exception occurs - message: {}", e.message) }
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ spring:
datasource:
hikari:
connection-timeout: 5000
minimum-idle: 10
maximum-pool-size: 100
minimum-idle: 2
maximum-pool-size: 5

hibernate:
show_sql: false
Expand All @@ -34,15 +34,15 @@ spring:
activate:
on-profile: deploy
jpa:
show-sql: true
show-sql: false
hibernate:
ddl-auto: none
generate-ddl: true
generate-ddl: false
datasource:
hikari:
connection-timeout: 5000
minimum-idle: 10
maximum-pool-size: 100
minimum-idle: 2
maximum-pool-size: 5

hibernate:
show_sql: false
Expand Down

0 comments on commit ef6fa3c

Please sign in to comment.