Skip to content

Commit

Permalink
BundleHandler max retries (#6118)
Browse files Browse the repository at this point in the history
* added max retries to bundle handler

* reset retries on callback

* extracted fetchRetries into separate function

* fixed fetch resolving

* added thumbnails for bundle example

* rewrote fetch retries without await inside loop

* removed images from PR
  • Loading branch information
kpal81xd authored Mar 7, 2024
1 parent b389618 commit d31a723
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/framework/handlers/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,23 @@ class BundleHandler extends ResourceHandler {
super(app, 'bundle');

this._assets = app.assets;
this.maxRetries = 0;
}

_fetchRetries(url, options, retries = 0) {
return new Promise((resolve, reject) => {
const tryFetch = () => {
fetch(url, options).then(resolve).catch((err) => {
retries++;
if (retries < this.maxRetries) {
Debug.error(`Bundle failed to load retrying (attempt ${retries}`);
tryFetch();
} else {
reject(err);
}
});
};
tryFetch();
});
}

load(url, callback) {
Expand All @@ -29,10 +45,10 @@ class BundleHandler extends ResourceHandler {
};
}

fetch(url.load, {
this._fetchRetries(url.load, {
mode: 'cors',
credentials: 'include'
}).then((res) => {
}, this.maxRetries).then((res) => {
const bundle = new Bundle();
callback(null, bundle);

Expand Down

0 comments on commit d31a723

Please sign in to comment.