Skip to content

Commit

Permalink
add error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
netzkollektiv committed May 23, 2024
1 parent c6f92ab commit e44e3a2
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/components/easycredit-checkout/easycredit-checkout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ export class EasycreditCheckout {
this.modal.close()
})

this.submitButtonClicked = true

this.addErrorHandler()
this.el.dispatchEvent(new CustomEvent('submit', {
bubbles : true,
cancelable : true,
Expand All @@ -170,6 +173,34 @@ export class EasycreditCheckout {
}))
}

addErrorHandler () {
let time = 4

let timeout = window.setTimeout(() => {
this.alert = 'Leider ist eine Zahlung mit easyCredit derzeit nicht möglich. Bitte verwenden Sie eine andere Zahlungsart oder wenden Sie sich an den Händler.'
this.modal.close()
console.error('No event handler handled the submit event of <easycredit-checkout> within ' + time +' seconds. Please check the integration.')
sendFeedback(this, { component: 'EasycreditCheckout', action: 'error' })
}, time * 1000)

// check for any request or page unload to determine if any event handler was reacting on the button click
var observer = new PerformanceObserver(function (batch) {
if (batch.getEntries()
.filter(entry => entry.initiatorType === 'xmlhttprequest' || entry.initiatorType === 'fetch')
.filter(entry => !entry.name.match(/\/api\/webcomponents\/v3\/feedback/))
.length > 0
) {
window.clearTimeout(timeout)
observer.disconnect()
}
});
observer.observe({ type: 'resource' });

window.onbeforeunload = function () {
window.clearTimeout(timeout)
}
}

getPaymentPlan () {
if (this.alert) {
return false
Expand Down

0 comments on commit e44e3a2

Please sign in to comment.