Add rate limit with Exponential Backoff
This commit is contained in:
@ -49,7 +49,12 @@ document.getElementById('serverForm').addEventListener('submit', async (e) => {
|
||||
|
||||
try {
|
||||
const response = await fetch(`/${edition}/${host}/${port}`);
|
||||
if (!response.ok) throw new Error('Request failed');
|
||||
if (!response.ok) {
|
||||
if (response.status === 429) {
|
||||
throw new Error('RateLimit');
|
||||
}
|
||||
throw new Error('Request failed');
|
||||
}
|
||||
const result = await response.json();
|
||||
|
||||
statusResult.classList.remove('hidden');
|
||||
@ -91,10 +96,17 @@ document.getElementById('serverForm').addEventListener('submit', async (e) => {
|
||||
}
|
||||
} catch (error) {
|
||||
statusResult.classList.remove('hidden');
|
||||
statusContent.innerHTML = `
|
||||
<p><strong class="text-blue-400">Status:</strong> <span class="text-red-400">Error</span></p>
|
||||
<p><strong class="text-blue-400">Error:</strong> An error occurred while checking the server status</p>
|
||||
`;
|
||||
if (error.message === 'RateLimit') {
|
||||
statusContent.innerHTML = `
|
||||
<p><strong class="text-blue-400">Status:</strong> <span class="text-yellow-400">Rate Limited</span></p>
|
||||
<p><strong class="text-blue-400">Message:</strong> You are sending requests too quickly. Please try again in a moment.</p>
|
||||
`;
|
||||
} else {
|
||||
statusContent.innerHTML = `
|
||||
<p><strong class="text-blue-400">Status:</strong> <span class="text-red-400">Error</span></p>
|
||||
<p><strong class="text-blue-400">Error:</strong> An error occurred while checking the server status</p>
|
||||
`;
|
||||
}
|
||||
} finally {
|
||||
// Hide loading spinner and re-enable button
|
||||
loadingSpinner.style.display = 'none';
|
||||
|
Reference in New Issue
Block a user