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() {
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)
})
}
}

Loading…
Cancel
Save