如何从Zuul过滤器中检索Json错误

时间:2016-07-18 19:12:20

标签: json netflix-zuul

我正在使用Postman向Zuul代理发送请求。 Zuul代理正在port 8085上运行 (http://localhost:8085/helloworld

我有一个zuul过滤器,并使用Spring RestTemplate从zuul过滤器调用微服务。微服务正在8089上运行

ResponseEntity<String> response = restTemplate.exchange(
        "http://localhost:8089/helloworld", HttpMethod.GET, entity, String.class);

当我从微服务获得成功的响应时,我在Postman中收到一个成功的JSON对象响应。

但是当微服务返回错误/异常时,zuul过滤器不会将其发送回调用客户端。即使微服务返回httpstatus message 200,我在Postman中得到一个空500 error的正文。

我尝试使用

发送微服务响应
ctx.setResponseBody(response.getBody());

基本上,这会将微服务的JSON响应转换为String。我能够在Postman中将响应作为String对象获得。

任何人都可以帮我解决如何从Zuul过滤器获取JSON对象的错误/异常响应。

0 个答案:

没有答案