From e1013586737e1cd6e1aafae1000db24c0b9701be Mon Sep 17 00:00:00 2001 From: tanghc Date: Fri, 30 Aug 2019 18:34:16 +0800 Subject: [PATCH] 2.0 --- .../zuul/configuration/ZuulErrorController.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) 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 78dd5142..dd769e6e 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; /** @@ -22,21 +23,24 @@ import javax.servlet.http.HttpServletResponse; @Slf4j public class ZuulErrorController implements ErrorController { - public static final String ERROR_PATH = "/error"; + private static final String ERROR_PATH = "/error"; /** * 错误最终会到这里来 */ @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(); - log.error("zuul网关报错,params:{}", ZuulContext.getApiParam(), throwable); + if (throwable == null) { + throwable = (Throwable) request.getAttribute("javax.servlet.error.exception"); + } + log.error("zuul网关报错,URL:{}, params:{}",request.getRequestURL().toString(), ZuulContext.getApiParam(), throwable); return this.buildResult(throwable); }