import org.springframework.stereotype.Component
import org.springframework.web.bind.annotation.ExceptionHandler
import org.springframework.web.bind.annotation.RestControllerAdvice
+import java.lang.reflect.UndeclaredThrowableException
import javax.servlet.http.HttpServletRequest
@ExceptionHandler
fun handleException(ex: Exception, request: HttpServletRequest): ResponseEntity<Any> {
logger.error { "Request unhandler exception, url<${request.requestURI}>, ex<${ex.cause}>" }
- if(ex is RequestParamCheckException){
+ val undeclared = if (ex is UndeclaredThrowableException) ex.undeclaredThrowable else ex
+ if (undeclared is RequestParamCheckException) {
return ResponseEntity.ok(ResponseBodyBuilder.create()
- .requestException(ex, "请求参数错误"))
- }else if(ex is TransactionException){
+ .requestException(undeclared, "请求参数错误"))
+ } else if (undeclared is TransactionException) {
return ResponseEntity.ok(ResponseBodyBuilder.create()
- .transException(ex, "业务处理错误"))
+ .transException(undeclared, "业务处理错误"))
}
return ResponseEntity.ok().body(ResponseBodyBuilder.create()
- .exception(TradeErrorCode.BUSINESS_DEAL_ERROR, ex.cause,"业务处理报错"))
+ .exception(TradeErrorCode.BUSINESS_DEAL_ERROR, undeclared, "业务处理报错"))
}
}