There is a user script (some variables and a husk, not very informative, I threw away):

(function (window, undefined) { // [2] нормализуем window var w; if (typeof unsafeWindow != undefined) { w = unsafeWindow; } else { w = window; } if (w.self != w.top) { return; } function start() { var read = getread(); checkResult(read); } function checkResult(last_read) { setTimeout(function() { if (last_read < getread()) { //1-ый блок } else if (last_read > getread()) { //2-ый блок } else { //3-ый блок checkResult(last_read); } }, 500); } function getread() { } function minimum_rate() { } function callnetwork() { } })(window); 

This script is a parsit online chat of a site. Sometimes the script does not receive a response from the site for the checkResult function. In this case, it fulfills the third condition (third block) and restarts the checkResult () function again. And so it can be several times. But sometimes, after repeated repetition of the third block of the checkResult () function, you can see the error "Failed to load resource: the server responded with a status of 429 ()" or some other error (for example, sometimes it can be 500 (), or 502 ()). In this case, the script hangs on the endless execution of the third block of the checkResult () function.

Please tell me how can I correct the script logic so that such an error does not occur?

  • for example, add try...catch and in the case of catch do not run the function - Grundy
  • As an option, if you know the error codes, then you can check them, if an error appears, then do not perform the checkResult function - Sergey Glazirin

0