adopted-ember-addons / adopted-ember-addons/ember-stripe-elements

Addon should retry upon script loading failure

Aperta
#22 1 commento 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
JavaScript
Stelle
19
Fork
22
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

I **very** often had issues in production where the Stripe script wouldn't load sending `Error: Could not load script https://js.stripe.com/v3/`to our Sentry logs. The route transition would then fail. My guess is network latency, DNS issues or maybe, yet unlikely, CDN issues with Stripe.

Before:
```javascript
// route.js
beforeModel() {
return this.get('stripe').load();
}
```

Le fix:
```javascript
// route.js
beforeModel(transition) {
const promise = this.get('stripe').load();
promise.catch(() => {
this.transitionTo('loading');
run.later(() => {
transition.retry();
}, 2000);
});
return promise;
}
```

Since loading Stripe in the routes beforeModel hook is the recommended approach, I think the retry logic should be implemented in the addon and be a default. I'm thinking of something like this:

```javascript
beforeModel() {
return this.get('stripe').load({retryCount: 5, retryDelay: 1000}); // defaults: {retryCount: 3, retryDelay: 2000}
}
```
... perhaps with a non-linear (exponential?) delay after every retry.

I'd like the maintainers‘ opinion on this approach.

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.