|
|
@ -1,31 +1,31 @@ |
|
|
|
package com.gitee.sop.gatewaycommon.zuul.configuration; |
|
|
|
package com.gitee.sop.gatewaycommon.zuul.controller; |
|
|
|
|
|
|
|
|
|
|
|
import com.gitee.sop.gatewaycommon.bean.ApiContext; |
|
|
|
import com.gitee.sop.gatewaycommon.bean.ApiContext; |
|
|
|
import com.gitee.sop.gatewaycommon.result.ResultExecutor; |
|
|
|
import com.gitee.sop.gatewaycommon.result.ResultExecutor; |
|
|
|
import com.gitee.sop.gatewaycommon.zuul.ZuulContext; |
|
|
|
import com.gitee.sop.gatewaycommon.zuul.ZuulContext; |
|
|
|
import com.netflix.zuul.context.RequestContext; |
|
|
|
import com.netflix.zuul.context.RequestContext; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springframework.web.bind.annotation.ControllerAdvice; |
|
|
|
import org.springframework.boot.web.servlet.error.ErrorController; |
|
|
|
import org.springframework.web.bind.annotation.ExceptionHandler; |
|
|
|
import org.springframework.web.bind.annotation.ExceptionHandler; |
|
|
|
import org.springframework.web.bind.annotation.ResponseBody; |
|
|
|
import org.springframework.web.bind.annotation.RequestMapping; |
|
|
|
|
|
|
|
import org.springframework.web.bind.annotation.RestController; |
|
|
|
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 处理网关自身异常 |
|
|
|
* zuul的异常处理 |
|
|
|
* |
|
|
|
* |
|
|
|
* @author tanghc |
|
|
|
* @author tanghc |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@ControllerAdvice |
|
|
|
|
|
|
|
@Slf4j |
|
|
|
@Slf4j |
|
|
|
public class ZuulErrorController { |
|
|
|
@RestController |
|
|
|
|
|
|
|
public class ZuulErrorController implements ErrorController { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 错误最终会到这里来 |
|
|
|
* 错误最终会到这里来 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@ExceptionHandler(Exception.class) |
|
|
|
@RequestMapping("/error") |
|
|
|
@ResponseBody |
|
|
|
|
|
|
|
public Object error(HttpServletRequest request, HttpServletResponse response) { |
|
|
|
public Object error(HttpServletRequest request, HttpServletResponse response) { |
|
|
|
RequestContext ctx = RequestContext.getCurrentContext(); |
|
|
|
RequestContext ctx = RequestContext.getCurrentContext(); |
|
|
|
if (ctx.getResponse() == null) { |
|
|
|
if (ctx.getResponse() == null) { |
|
|
@ -45,4 +45,8 @@ public class ZuulErrorController { |
|
|
|
return resultExecutor.buildErrorResult(RequestContext.getCurrentContext(), throwable); |
|
|
|
return resultExecutor.buildErrorResult(RequestContext.getCurrentContext(), throwable); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public String getErrorPath() { |
|
|
|
|
|
|
|
return "/error"; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |