From ef08956df6a85cb4409780312dbf639c7aa7bb75 Mon Sep 17 00:00:00 2001 From: tanghc Date: Fri, 30 Aug 2019 18:26:09 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A0=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../zuul/configuration/ZuulErrorController.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/zuul/configuration/ZuulErrorController.java b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/zuul/configuration/ZuulErrorController.java index ca4870f1..6d50a6e0 100644 --- a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/zuul/configuration/ZuulErrorController.java +++ b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/zuul/configuration/ZuulErrorController.java @@ -11,6 +11,7 @@ import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; +import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; /** @@ -29,13 +30,16 @@ public class ZuulErrorController implements ErrorController { */ @RequestMapping(ERROR_PATH) @ResponseBody - public Object error(HttpServletResponse response) { + public Object error(HttpServletRequest request, HttpServletResponse response) { RequestContext ctx = RequestContext.getCurrentContext(); if (ctx.getResponse() == null) { ctx.setResponse(response); } ctx.setResponseStatusCode(HttpStatus.OK.value()); Throwable throwable = ctx.getThrowable(); + if (throwable == null) { + throwable = (Throwable) request.getAttribute("javax.servlet.error.exception"); + } log.error("请求错误,params:{}", ZuulContext.getApiParam(), throwable); return this.buildResult(throwable); }