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

Addon should retry upon script loading failure

Ouverte
#22 1 commentaire 0 réactions 0 personnes assignées Voir sur GitHub
Langage dominant
JavaScript
Étoiles
19
Forks
22
Métriques de merge des PR
Aucune PR mergée en 30 j

Description

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.

Guide de contribution

Ouvrir le guide de contribution

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.