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.
This commit is contained in:
Leonid Nikitin 2023-11-25 19:59:54 +06:00
parent 876fcc9e6b
commit c57a81d76b
Signed by: kor-elf
GPG Key ID: 604A019EB118CAC4

View File

@ -152,7 +152,13 @@
}, },
body: JSON.stringify(data) body: JSON.stringify(data)
}) })
.then(response => response.json()) .then(response => {
if (response.status === 429) {
setError('Вы превысили количество попыток. Обновите каптчу.', button);
return
}
return response.json();
})
.then(function (data) { .then(function (data) {
if (typeof data.errors !== 'undefined') { if (typeof data.errors !== 'undefined') {
let errorMessage = ''; let errorMessage = '';