org.springframework.cloud.gateway.support.TimeoutException Java Examples

The following examples show how to use org.springframework.cloud.gateway.support.TimeoutException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FebsGatewayExceptionHandler.java    From FEBS-Cloud with Apache License 2.0 5 votes vote down vote up
/**
 * 异常处理,定义返回报文格式
 */
@Override
protected Map<String, Object> getErrorAttributes(ServerRequest request, boolean includeStackTrace) {
    Throwable error = super.getError(request);
    log.error(
            "请求发生异常,请求URI:{},请求方法:{},异常信息:{}",
            request.path(), request.methodName(), error.getMessage()
    );
    String errorMessage;
    if (error instanceof NotFoundException) {
        String serverId = StringUtils.substringAfterLast(error.getMessage(), "Unable to find instance for ");
        serverId = StringUtils.replace(serverId, "\"", StringUtils.EMPTY);
        errorMessage = String.format("无法找到%s服务", serverId);
    } else if (StringUtils.containsIgnoreCase(error.getMessage(), "connection refused")) {
        errorMessage = "目标服务拒绝连接";
    } else if (error instanceof TimeoutException) {
        errorMessage = "访问服务超时";
    } else if (error instanceof ResponseStatusException
            && StringUtils.containsIgnoreCase(error.getMessage(), HttpStatus.NOT_FOUND.toString())) {
        errorMessage = "未找到该资源";
    } else {
        errorMessage = "网关转发异常";
    }
    Map<String, Object> errorAttributes = new HashMap<>(3);
    errorAttributes.put("message", errorMessage);
    return errorAttributes;
}
 
Example #2
Source File: FwGatewayExceptionHandler.java    From fw-spring-cloud with Apache License 2.0 5 votes vote down vote up
/**
 * 异常处理,定义返回报文格式
 */
@Override
protected Map<String, Object> getErrorAttributes(ServerRequest request, boolean includeStackTrace) {
    Throwable error = super.getError(request);
    log.error(
            "请求发生异常,请求URI:{},请求方法:{},异常信息:{}",
            request.path(), request.methodName(), error.getMessage()
    );
    String errorMessage;
    if (error instanceof NotFoundException) {
        String serverId = StringUtils.substringAfterLast(error.getMessage(), "Unable to find instance for ");
        serverId = StringUtils.replace(serverId, "\"", StringUtils.EMPTY);
        errorMessage = String.format("无法找到%s服务", serverId);
    } else if (StringUtils.containsIgnoreCase(error.getMessage(), "connection refused")) {
        errorMessage = "目标服务拒绝连接";
    } else if (error instanceof TimeoutException) {
        errorMessage = "访问服务超时";
    } else if (error instanceof ResponseStatusException
            && StringUtils.containsIgnoreCase(error.getMessage(), HttpStatus.NOT_FOUND.toString())) {
        errorMessage = "未找到该资源";
    } else {
        errorMessage = "网关转发异常";
    }
    Map<String, Object> errorAttributes = new HashMap<>(2);
    errorAttributes.put("msg", errorMessage);
    errorAttributes.put("code", HttpStatus.INTERNAL_SERVER_ERROR.value());
    return errorAttributes;
}