-
Notifications
You must be signed in to change notification settings - Fork 275
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ability to inspect which scripts failed #152
Comments
I have been playing with Looking at the code, I believe that the behavior described in this ticket is caused by the fact that internally A potential enhancement would be to modify the I wouldn't mind working on a PR that implements this solution If the project's core members believe that this would be useful. In the meantime, you can have a workaround by doing something like this: // define one valid URL and two invalid ones
var urls = [
'https://badurl1/x.js',
'https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0-alpha1/jquery.min.js',
'https://badurl2/y.js'
],
failedUrls = [],
i;
// closure that lets us deal with each url individually
var getResource = function (url) {
basket.require({url: url}).then(function () {}, function (err) {
// deal with the failures here
// for this example we just push the failed url to an array to be checked later
failedUrls.push(url);
});
};
// get the resources
for (i = 0; i < urls.length; i++) {
getResource(urls[i]);
}
// wait a little bit for all the 'requires' to be fullfilled or rejected
// and check the 'failedUrls' array to see which ones failed
setTimeout(function () {
console.log(failedUrls) // expect: ["https://badurl1/x.js", "https://badurl2/y.js"]
}, 500); Cheers! |
I'm also happy to help out with PR, can contribute 2 hours if needed. Thoughts @sindresorhus / @addyosmani ? |
As an extension to the answer given by @reinaldo13, it might also be nice to have failure reason. For example; basket.require(
{ url: '//example.com', key: 'jquery' },
{ url: '//example.com', key: 'other' })
.then(function(){}, function(err) {
console.log(err.failed) // [ ['jquery', 'timeout', Error()], ]
); Or alternatively, you could even add nice chaining;
|
this feature would make basket.js amazing! we often end up using teamviewer for this, which is a pain. |
@sindresorhus / @addyosmani - Can you spare 5 minutes to review this before commit time for a PR? |
@sindresorhus I'm personally fine with the community extending the inspection capabilities of basket. We'll need to review how large an impact this has on source as per any PR, but otherwise curious what this would look like, @foxx 👍 |
Thanks for the update and apologies for the delay, I'll get a PR submitted this week |
What would be the most suitable way of turning on "trackFailures" ? An options object passed after the array of needed resources, so it only applies to those resources:
Or a global config option basket.trackFailures = true ? |
It would be nice to have the ability to inspect which scripts failed to load on the error() handler.
This would allow me to determine if the failed script was in the "important" list or not, and send the error to a collection service where needed. For example, jquery would be a fatal error where as a third party tracking library might not be.
Currently it just seems to show this in console;
Ideally it would be good to be able to do something like;
The text was updated successfully, but these errors were encountered: