summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Gay <david@davidgay.org>2021-06-04 10:35:52 -0400
committerDavid Gay <david@davidgay.org>2021-06-04 10:35:52 -0400
commit8c83a0a78cf9e02de782f46337a686208e0ed7ac (patch)
tree8634d503d5eae1d63401066a2b2fb475e2e2165a
parent8206cac29ec2ce86e0b0a68360ec714b573e13f6 (diff)
Add back in some timer POST error handling
-rw-r--r--app/javascript/controllers/timer_controller.js28
1 files changed, 20 insertions, 8 deletions
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.");
+ }
+ },
+ });
+ }
}