chore:改进系统对未处理异常信息的展示
authorTang Cheng <cheng.tang@supwisdom.com>
Wed, 19 Jun 2019 03:46:20 +0000 (11:46 +0800)
committerTang Cheng <cheng.tang@supwisdom.com>
Wed, 19 Jun 2019 03:46:20 +0000 (11:46 +0800)
src/main/kotlin/com/supwisdom/dlpay/api/advices.kt

index 5dff2a5..0a893ea 100644 (file)
@@ -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<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, "业务处理报错"))
     }
 }