From: Tang Cheng Date: Wed, 19 Jun 2019 03:46:20 +0000 (+0800) Subject: chore:改进系统对未处理异常信息的展示 X-Git-Tag: 1.0.0^2~164 X-Git-Url: https://source.supwisdom.com/gerrit/gitweb?a=commitdiff_plain;h=aeb5f7c2e17dc6595352286e62c8b97ee624ba68;p=epayment%2Ffood_payapi.git chore:改进系统对未处理异常信息的展示 --- diff --git a/src/main/kotlin/com/supwisdom/dlpay/api/advices.kt b/src/main/kotlin/com/supwisdom/dlpay/api/advices.kt index 5dff2a53..0a893ea3 100644 --- a/src/main/kotlin/com/supwisdom/dlpay/api/advices.kt +++ b/src/main/kotlin/com/supwisdom/dlpay/api/advices.kt @@ -14,6 +14,7 @@ import org.springframework.http.ResponseEntity 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 @@ -24,16 +25,17 @@ class RestControllerAdvice { @ExceptionHandler fun handleException(ex: Exception, request: HttpServletRequest): ResponseEntity { 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, "业务处理报错")) } }