How to map response of rate limit quota into exception? #2036
Replies: 2 comments 1 reply
-
Hi Sarah! You are trying to add custom middleware into Ocelot pipeline (middleware conveyor) by this code: app.Use(async (context, next) =>
{
await next(context);
if (context.Response.StatusCode == 429)
{
throw new RateLimitException("Rate limit exceed");
}
}); It is a quite risky, because you don't control and you don't know the order of middleware execution. What is the goal of your throwing of custom exception? Why not to customize Rate Limiting by options? "RateLimitOptions": {
"QuotaExceededMessage": "Customize Tips!", // custom message for clients
"HttpStatusCode": 123, // custom status code for clients
} See the docs: Rate Limiting | Ocelot Own Implementation Regarding execution order of your custom middleware ... I recommend to read the docs to understand Middleware Injection better. Let me know if it won't help. |
Beta Was this translation helpful? Give feedback.
-
hi raman, I want the response to be standard problem details. |
Beta Was this translation helpful? Give feedback.
-
I want to map response of rate limit quota into exception,
But its not even reaching my
Startup.cs
... Any insight how to do so?Beta Was this translation helpful? Give feedback.
All reactions