Rise web pages on custom lms - custom error handler

Mar 26, 2019

Hi to everybody,

we are currently using rise to produce courses linked to our internal LRS.

However, due to many possible cases, from time to time the LRS has become temporarily unavailable, returning 50x errors to several of the course internal xAPI calls. We would like to be able to warn our customers about it, because they won't be able to see their past progress and the new progress won't be saved.

Is there a way to, somehow, manage this kind of errors within a Rise course? I have seen that index.html elegantly publishes a javascript object with some basic functionalities... but I could not find any documentation about it, and function names seem unrelated to our needs.

Does anybody have any hint on this?

Thank you,

Matteo

1 Reply
Fluentify UK LTD

I answer myself to this.. maybe it could be useful to someone.

I ended up creating a custom xmlhttprequest object able to call a function when he receives 500 errors. 

/* * *
* Custom error manager wrapping error 500s.
*/

var httpwrap = function(manager){
var _send = XMLHttpRequest.prototype.send;
window.XMLHttpRequest.prototype.send = function(){
var onerrorx = this.onerror,
handled = false;
this.onerror = function() {
if (!handled) {
handled = true;
manager(arguments);
}
if (onerrorx) return onerrorx.apply(this, arguments);
}
this.addEventListener('error', function() {
if (!handled) {
handled = true;
manager(arguments);
}
if (onerrorx) return onerrorx.apply(this, arguments);
});
var ret;
try {
ret = _send.apply(this, arguments);
} catch (e) {
if (!handled) {
handled = true;
manager(arguments);
}
}
if (ret == void(0) && this.status > 400) {
if (!handled) {
handled = true;
manager(this);
}
}
return ret;
};
};

//Usage example
httpwrap(function(error) {
alert('yep, that is an error');
})

This discussion is closed. You can start a new discussion or contact Articulate Support.