Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/384.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在Zuul中捕获HystrixTimeout异常_Java_Spring Boot_Exception_Netflix Zuul_Hystrix - Fatal编程技术网

Java 如何在Zuul中捕获HystrixTimeout异常

Java 如何在Zuul中捕获HystrixTimeout异常,java,spring-boot,exception,netflix-zuul,hystrix,Java,Spring Boot,Exception,Netflix Zuul,Hystrix,当web服务在一段时间(超时)内没有响应并抛出HystrixTimeout异常时,我想在ZuFilter中捕获HystrixTimeout异常。我怎么办 注意:在ZuulFilter中,我捕获自定义异常。就像下面的代码一样 @Override public Object run() { final RequestContext context = RequestContext.getCurrentContext(); final Object throwable = contex

当web服务在一段时间(超时)内没有响应并抛出HystrixTimeout异常时,我想在ZuFilter中捕获HystrixTimeout异常。我怎么办

注意:在ZuulFilter中,我捕获自定义异常。就像下面的代码一样

@Override
public Object run() {
    final RequestContext context = RequestContext.getCurrentContext();
    final Object throwable = context.get(THROWABLE_KEY);

    if (throwable instanceof ZuulException) {
        ZuulException zuulException = (ZuulException) throwable;
        
    }
    return null;
}

这个问题不是我真正的问题。首先,我明白这一点。因为我的应用程序将SocketTimeoutException作为基本例外。所以,如果我可以捕获SocketTimeoutException,我可以处理这个问题,但是对于这个解决方案,我需要获取异常的原因。我写了一个类似下面代码的方法

private Throwable findRightException(Throwable th) {
        Throwable throwable = th;
        if (throwable.getCause() == null || throwable.getCause() instanceof SocketTimeoutException) {
            return throwable.getCause();
        }
        return findRightException(throwable.getCause());

因为正如我所悲伤的,主要的例外是SocketTimeoutException