From c57a81d76b7707c60e233ec2908d0417daadf570 Mon Sep 17 00:00:00 2001 From: Leonid Nikitin Date: Sat, 25 Nov 2023 19:59:54 +0600 Subject: [PATCH] Handle server rate limit in script.js In the 'then' function of our AJAX request in script.js, I've added a condition to check for a response status of 429 which indicates too many requests. If this status is encountered, an error message will be shown prompting the user to refresh their CAPTCHA. This is to prevent the user from making excessive attempts unbeknownst to them. --- exmplate/script.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/exmplate/script.js b/exmplate/script.js index 733eb88..d31dcf1 100644 --- a/exmplate/script.js +++ b/exmplate/script.js @@ -152,7 +152,13 @@ }, body: JSON.stringify(data) }) - .then(response => response.json()) + .then(response => { + if (response.status === 429) { + setError('Вы превысили количество попыток. Обновите каптчу.', button); + return + } + return response.json(); + }) .then(function (data) { if (typeof data.errors !== 'undefined') { let errorMessage = '';