diff --git a/app/javascript/controllers/soft_validations_controller.js b/app/javascript/controllers/soft_validations_controller.js index 963dd7a76..a408e4460 100644 --- a/app/javascript/controllers/soft_validations_controller.js +++ b/app/javascript/controllers/soft_validations_controller.js @@ -5,8 +5,13 @@ export default class extends Controller { initialize() { let url = window.location.href + "/soft_validations" + this.fetch_retry(url, { headers: { accept: "application/json" } }, 2) + } + + fetch_retry(url, options, n) { + let self = this let div = this.overrideTarget - fetch(url, { headers: { accept: "application/json" } }) + fetch(url, options) .then(response => response.json()) .then((response) => { if(response["show"]){ @@ -22,7 +27,10 @@ export default class extends Controller { button.checked = false }) } - } - ) + }) + .catch(function(error) { + if (n === 1) throw error + return self.fetch_retry(url, options, n - 1) + }) } }