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

Addon should retry upon script loading failure

Abierto
#22 1 comentario 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
JavaScript
Estrellas
19
Forks
22
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

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.

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.