retry after secomds
This commit is contained in:
parent
911f840af5
commit
f304437ed8
|
@ -18,7 +18,7 @@ public class RateLimitInterceptor implements HandlerInterceptor {
|
||||||
|
|
||||||
private static final String HEADER_API_KEY = "X-api-key";
|
private static final String HEADER_API_KEY = "X-api-key";
|
||||||
private static final String HEADER_LIMIT_REMAINING = "X-Rate-Limit-Remaining";
|
private static final String HEADER_LIMIT_REMAINING = "X-Rate-Limit-Remaining";
|
||||||
private static final String HEADER_RETRY_AFTER = "X-Rate-Limit-Retry-After-Milliseconds";
|
private static final String HEADER_RETRY_AFTER = "X-Rate-Limit-Retry-After-Seconds";
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private PricingPlanService pricingPlanService;
|
private PricingPlanService pricingPlanService;
|
||||||
|
@ -44,10 +44,10 @@ public class RateLimitInterceptor implements HandlerInterceptor {
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
long waitForRefillMilli = probe.getNanosToWaitForRefill() % 1_000_000;
|
long waitForRefill = probe.getNanosToWaitForRefill() % 1_000_000_000;
|
||||||
|
|
||||||
response.sendError(HttpStatus.TOO_MANY_REQUESTS.value(), "You have exhausted your API Request Quota"); // 429
|
response.sendError(HttpStatus.TOO_MANY_REQUESTS.value(), "You have exhausted your API Request Quota"); // 429
|
||||||
response.addHeader(HEADER_RETRY_AFTER, String.valueOf(waitForRefillMilli));
|
response.addHeader(HEADER_RETRY_AFTER, String.valueOf(waitForRefill));
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ enum PricingPlan {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
Bandwidth getLimit() {
|
Bandwidth getLimit() {
|
||||||
return Bandwidth.classic(2, Refill.intervally(2 , Duration.ofHours(1)));
|
return Bandwidth.classic(20, Refill.intervally(20, Duration.ofHours(1)));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue