Skip to content
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

trackFailures option #156

Open
wants to merge 2 commits into
base: gh-pages
Choose a base branch
from
Open

Conversation

MarkusPint
Copy link

A basic option to track & inspect loading failures as described in #152

  • Added detection of timeout error.
  • Added 3 tests.
  • This will not work with thenRequire() chaining.

Usage:

basket
    .require([{ url: 'missing.js' }], { trackFailures: true })
    .then(function (responses) {
        if ( responses[0].state === "rejected" ) {
            console.log(responses[0].reason.message); // Not Found
        }
    }, function(error) {
        // This is not called
    });

@addyosmani
Copy link
Owner

cc @foxx

@foxx
Copy link

foxx commented Nov 26, 2015

I'm not keen on the idea of changing the promise chaining based on an argument, as it doesn't feel clean imho. Instead of trackFailures, perhaps we could use a third argument as seen in other thenables, which would be used to track progress, see here.

For example;

basket.require(
    { url: '//example.com', key: 'jquery' },
    { url: '//example.com', key: 'other' })
    .then(function(){
        console.log("All loaded okay");
    }, function(err) {
        console.log("Failed to load all scripts");
    }, function(event, args) {
        // event=loaderror
        // args={key:'jquery':, url: 'http://...', reason: ..., err: ...]
     })

Another option is introducing on and fail, like such;

basket.require(
    { url: '//example.com', key: 'jquery' },
    { url: '//example.com', key: 'other' })
    .then(function(){
        console.log("All loaded okay");
    })
    .fail(function(err) {
        console.log("Failed to load all scripts");
    })
    .on('loaderror', function(key, url, reason, err) {
        // {key:'jquery':, url: 'http://...', reason: ..., err: ...]
     })

These all get the same job done, just exposed in different ways. @addyosmani do you have any preference?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants