Limites de Taxa da AppFolio | sed 's/\b(.)/\u\1/g'
Visão Geral
A API AppFolio impõe limites de taxa por parceiro. Implemente limitação para permanecer dentro dos limites.
Gerenciador de Limites de Taxa
import Bottleneck from "bottleneck";
const limiter = new Bottleneck({
maxConcurrent: 5,
minTime: 200, // 5 requisições/segundo no máximo
});
async function throttledRequest(client: any, path: string) {
return limiter.schedule(() => client.http.get(path));
}
// Retry para 429
async function withRetry(fn: () => Promise<any>, maxRetries = 3) {
for (let i = 1; i <= maxRetries; i++) {
try { return await fn(); }
catch (err: any) {
if (err.response?.status !== 429 || i === maxRetries) throw err;
const delay = Math.min(1000 * Math.pow(2, i), 30000);
await new Promise(r => setTimeout(r, delay));
}
}
}