Open tianmingxing opened 5 years ago
The configuration object for the rate limiter filter allows you to configure the status code https://github.com/spring-cloud/spring-cloud-gateway/blob/4ea874a3c6ffb50b59ec05a19847ab8b10037d30/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/factory/RequestRateLimiterGatewayFilterFactory.java#L125
In addition to modifying the response code, I also need to define the information returned. I want to be able to return what the client can parse when triggering a current limit, as shown below:
{
"timestamp": "2019-01-20T19:55:39.814",
"code": 1008,
"message": "too many connections."
}
Does your error attributes class have the proper order? https://www.baeldung.com/spring-webflux-errors
The code I've written is shown below, and the component startup sequence is the same as in the article.
I want to catch the exception caused by the current limit, but it doesn't seem to be a mistake, so it is not caught. But I need to customize the response content in this case, otherwise the client can't parse the recognition.
I dont think the rate request filter is actually returning an exception when there are too many request so I dont think the handler would come into play
It's not currently possible since an exception isn't thrown.
@spencergibb If there is an exception thrown, this problem can be easily handled, so in the face of such a realistic situation, can you provide some good suggestions? Thank you!
Is there more information available on this topic so far?
I don't have one other than a custom filter.
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.
@spencergibb This problem is universal and it seems to be improved as a feature in the next version. I look forward to your best solution, thank you!
+1 I will have to create my own filter until this is possible.
DefaultErrorAttributes
to implement, but found that this exception was not caught at all.