feat: improved timeout handling for api client

This commit is contained in:
Björn Fromme
2026-03-16 11:59:11 +01:00
parent be90248fc7
commit 37924841e1
14 changed files with 139 additions and 14 deletions
+11
View File
@@ -12,16 +12,19 @@ export default class extends Controller {
// Bind event handlers to preserve context
this.boundHandleBeforeRequest = this.handleBeforeRequest.bind(this)
this.boundHandleAfterRequest = this.handleAfterRequest.bind(this)
this.boundHandleTimeout = this.handleTimeout.bind(this)
// Listen to HTMX events
document.body.addEventListener('htmx:beforeRequest', this.boundHandleBeforeRequest)
document.body.addEventListener('htmx:afterRequest', this.boundHandleAfterRequest)
document.body.addEventListener('htmx:timeout', this.boundHandleTimeout)
}
disconnect() {
// Clean up event listeners
document.body.removeEventListener('htmx:beforeRequest', this.boundHandleBeforeRequest)
document.body.removeEventListener('htmx:afterRequest', this.boundHandleAfterRequest)
document.body.removeEventListener('htmx:timeout', this.boundHandleTimeout)
// Clear any pending timeout
if (this.debounceTimeout) {
@@ -65,6 +68,14 @@ export default class extends Controller {
this.hide()
}
handleTimeout(event) {
// Hide loading indicator
this.hide()
// Show user-friendly error message
alert('Die Anfrage hat zu lange gedauert. Bitte versuchen Sie es erneut. Falls das Problem weiterhin besteht, kontaktieren Sie bitte unseren Support.')
}
show() {
this.isVisible = true
this.indicatorTarget.classList.remove(this.hiddenClass)