Browse Source

Add a retry to our fetch so tests are more resilient to intermittent network issues

pull/82/head
baarkerlounger 4 years ago
parent
commit
581de76045
  1. 14
      app/javascript/controllers/soft_validations_controller.js

14
app/javascript/controllers/soft_validations_controller.js

@ -5,8 +5,13 @@ export default class extends Controller {
initialize() { initialize() {
let url = window.location.href + "/soft_validations" 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 let div = this.overrideTarget
fetch(url, { headers: { accept: "application/json" } }) fetch(url, options)
.then(response => response.json()) .then(response => response.json())
.then((response) => { .then((response) => {
if(response["show"]){ if(response["show"]){
@ -22,7 +27,10 @@ export default class extends Controller {
button.checked = false button.checked = false
}) })
} }
} })
) .catch(function(error) {
if (n === 1) throw error
return self.fetch_retry(url, options, n - 1)
})
} }
} }

Loading…
Cancel
Save