From 8c83a0a78cf9e02de782f46337a686208e0ed7ac Mon Sep 17 00:00:00 2001 From: David Gay Date: Fri, 4 Jun 2021 10:35:52 -0400 Subject: Add back in some timer POST error handling --- app/javascript/controllers/timer_controller.js | 28 ++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) (limited to 'app/javascript') diff --git a/app/javascript/controllers/timer_controller.js b/app/javascript/controllers/timer_controller.js index b13188a..30e64cc 100644 --- a/app/javascript/controllers/timer_controller.js +++ b/app/javascript/controllers/timer_controller.js @@ -13,6 +13,7 @@ export default class extends Controller { connect() { if (!this.timerInterval) this.startUpdating(); this.timerTarget.textContent = Math.ceil(this.timeRemainingValue); + this.postFailures = 0; } startUpdating() { @@ -29,15 +30,26 @@ export default class extends Controller { } else { clearInterval(controller.timerInterval); controller.timerInterval = null; - Rails.ajax({ - type: "POST", - url: controller.postUrlValue, - success: () => { - }, - error: () => { - }, - }); + controller.finishActivity(); } }, 10); } + + finishActivity() { + let controller = this; + Rails.ajax({ + type: "POST", + url: controller.postUrlValue, + error: () => { + this.postFailures++; + if (this.postFailures < 5) { + setTimeout(controller.finishActivity, 1000); + } else { + alert("There was an error completing your activity. If your internet connection is otherwise working," + + " please report this issue, mentioning what you were" + + " doing at the time. Check if refreshing the page resolves this issue, and mention that as well."); + } + }, + }); + } } -- cgit v1.2.3