adlnet / xAPIWrapper

Wrapper to simplify communication to an LRS
https://adlnet.gov/projects/xapi/
Apache License 2.0
214 stars 114 forks source link

Stop sending statements when about internet #167

Closed iliakut closed 4 years ago

iliakut commented 4 years ago

After losing the connection to the internet, the last statement is not send (because of no connection) I see an error in network, it is ok. But after reconnection to the internet statements don't send any more. Is there any solution?

System: any Browser: Chrome 80

adl-trey commented 4 years ago

Hey there!

So the wrapper doesn't do anything like that directly, but you could set that up using the strict callbacks.

ADL.XAPIWrapper.changeConfig({
    auth: "Basic " + btoa("your:auth"),
    endpoint: "http://your.lrs",

    strictCallbacks: true, // <--- Enable this
});

With the strictCallbacks enabled, you can check if the wrapper encountered an error when sending your statement. In your case, you might want to cache problematic statements and retry them later.

ADL.XAPIWrapper.sendStatement(stmt, function(err, res, body) {
    if (err) {
        // Add this statement to some kind of backlog
        return;
    }
});

Then somewhere else, you might have something like this running:

setInterval(function() {
    // Try sending those statements again and dump the backlog
}, 2000);
iliakut commented 4 years ago

Hey there!

So the wrapper doesn't do anything like that directly, but you could set that up using the strict callbacks.

ADL.XAPIWrapper.changeConfig({
    auth: "Basic " + btoa("your:auth"),
    endpoint: "http://your.lrs",

    strictCallbacks: true, // <--- Enable this
});

With the strictCallbacks enabled, you can check if the wrapper encountered an error when sending your statement. In your case, you might want to cache problematic statements and retry them later.

ADL.XAPIWrapper.sendStatement(stmt, function(err, res, body) {
    if (err) {
        // Add this statement to some kind of backlog
        return;
    }
});

Then somewhere else, you might have something like this running:

setInterval(function() {
    // Try sending those statements again and dump the backlog
}, 2000);

tnank you! I did something like this. The problem was: when no response from server (no internet for example) the promise was not rejected. I added setTimeot(...) and if it is a problem with the response promise rejects automatically.