diff --git a/bootstrap/src/main/kotlin/com/ddd/teople/bootstrap/api/auth/AuthController.kt b/bootstrap/src/main/kotlin/com/ddd/teople/bootstrap/api/auth/AuthController.kt index 85955f3..21b17ef 100644 --- a/bootstrap/src/main/kotlin/com/ddd/teople/bootstrap/api/auth/AuthController.kt +++ b/bootstrap/src/main/kotlin/com/ddd/teople/bootstrap/api/auth/AuthController.kt @@ -23,8 +23,6 @@ class AuthController( */ @GetMapping("/auth/token") fun token(@Validated input: TokenRequest): CommonResponse { - log.info("[token] input: $input") - val result = generateTokenUseCase.reIssueToken(input.token) return CommonResponse.success(data = TokenResponse.of(input = result)) } diff --git a/bootstrap/src/main/kotlin/com/ddd/teople/bootstrap/global/aop/AuthenticationAspect.kt b/bootstrap/src/main/kotlin/com/ddd/teople/bootstrap/global/aop/AuthenticationAspect.kt index 10fbb27..51afe57 100644 --- a/bootstrap/src/main/kotlin/com/ddd/teople/bootstrap/global/aop/AuthenticationAspect.kt +++ b/bootstrap/src/main/kotlin/com/ddd/teople/bootstrap/global/aop/AuthenticationAspect.kt @@ -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 diff --git a/bootstrap/src/main/kotlin/com/ddd/teople/bootstrap/global/common/constants/ResponseCode.kt b/bootstrap/src/main/kotlin/com/ddd/teople/bootstrap/global/common/constants/ResponseCode.kt index 23fcc2a..d7a48b3 100644 --- a/bootstrap/src/main/kotlin/com/ddd/teople/bootstrap/global/common/constants/ResponseCode.kt +++ b/bootstrap/src/main/kotlin/com/ddd/teople/bootstrap/global/common/constants/ResponseCode.kt @@ -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"), diff --git a/bootstrap/src/main/kotlin/com/ddd/teople/bootstrap/global/common/handler/CommonExceptionHandler.kt b/bootstrap/src/main/kotlin/com/ddd/teople/bootstrap/global/common/handler/CommonExceptionHandler.kt index 302900b..60c3646 100644 --- a/bootstrap/src/main/kotlin/com/ddd/teople/bootstrap/global/common/handler/CommonExceptionHandler.kt +++ b/bootstrap/src/main/kotlin/com/ddd/teople/bootstrap/global/common/handler/CommonExceptionHandler.kt @@ -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 @@ -21,50 +22,80 @@ class CommonExceptionHandler { @ExceptionHandler(BindException::class) @ResponseStatus(value = HttpStatus.BAD_REQUEST) @ResponseBody - fun bindException(e: BindException): CommonResponse = + fun handleBindException(e: BindException): CommonResponse = 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 = + 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 = + fun handleJwtInvalidException(e: JwtInvalidException): CommonResponse = 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 = + fun handleAuthenticationException(e: AuthenticationException): CommonResponse = 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 = + fun handleCoupleCodeInvalidException(e: CoupleCodeInvalidException): CommonResponse = 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 = + fun handleDataNotFoundException(e: DataNotFoundException): CommonResponse = 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 = + 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 = + 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) } } \ No newline at end of file diff --git a/framework/framework-mysql/src/main/resources/application-framework-mysql.yaml b/framework/framework-mysql/src/main/resources/application-framework-mysql.yaml index d62f1f0..2622a80 100644 --- a/framework/framework-mysql/src/main/resources/application-framework-mysql.yaml +++ b/framework/framework-mysql/src/main/resources/application-framework-mysql.yaml @@ -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 @@ -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