当请求需要更多时间处理时,Zuul代理服务器抛出内部服务器错误

时间:2018-06-21 08:59:00

标签: microservices netflix-zuul proxy-server

Zuul Proxy Error

请求在服务中花费更多时间处理时出现此错误。但是Zuul返回内部服务器错误的响应

使用zuul 2.0.0.RC2版本

1 个答案:

答案 0 :(得分:0)

据我了解,如果服务没有响应,路由丢失等,您可以设置/ error端点以向用户传递自定义响应。 例如:

@Controller
public class CustomErrorController implements ErrorController {

    @RequestMapping(value = "/error", produces = "application/json")
    public @ResponseBody
    ResponseEntity error(HttpServletRequest request) {
        // consider putting these in a try catch
        Integer statusCode = (Integer)request.getAttribute("javax.servlet.error.status_code");
        Throwable exception = (Throwable)request.getAttribute("javax.servlet.error.exception");

        // maybe add some error logging here, e.g. original status code, exception, traceid, etc.

        // consider a better error to the user here
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{'message':'some error happened', 'trace_id':'some-trace-id-here'}");
    }

    @Override
    public String getErrorPath() {
        return "/error";
    }
}