正常情况下被限流会自动返回
状态码为429,消息体为:
{
"timestamp": 1560396819329,
"status": 429,
"error": "Too Many Requests",
"exception": "com.netflix.zuul.exception.ZuulException",
"message": "429"
}
下面它变成状态码为200,消息体自定义:
我是在zuul网关下建立一个全局返回状态监听:继承 org.springframework.boot.autoconfigure.web.DefaultErrorAttributes 并且重写了 getErrorAttributes 方法:
package io.spring.cloud.zuul.demo;
import org.springframework.boot.autoconfigure.web.DefaultErrorAttributes;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestAttributes;
import java.util.HashMap;
import java.util.Map;
@Component
public class DemoErrorAttribute extends DefaultErrorAttributes {
@Override
public Map<String, Object> getErrorAttributes(RequestAttributes requestAttributes, boolean includeStackTrace) {
Map<String, Object> res