Skip to Content

errorMitigation()

Automatically attempt to detect and mitigate fixable errors that occur such as broken images.

JavaScript February 22, 2017

Usage

This function runs automatically, so it is not called manually. Is this incorrect?

Source File

Located in /assets/js/nebula.js on line 3586.

JavaScript
nebula.errorMitigation = function(){
    //Try to fall back to .png on .svg errors. Else log the broken image.
    jQuery('img').on('error', function(){
        var thisImage = jQuery(this);
        var imagePath = thisImage.attr('src');
        if ( imagePath.split('.').pop() === 'svg' ){
            var fallbackPNG = imagePath.replace('.svg', '.png');
            jQuery.get(fallbackPNG).done(function(){
                thisImage.prop('src', fallbackPNG);
                thisImage.removeClass('svg');
            }).fail(function() {
                ga('send', 'exception', {'exDescription': '(JS) Broken Image: ' + imagePath, 'exFatal': false});
                nebula.nv('event', 'Broken Image');
            });
        } else {
            ga('send', 'exception', {'exDescription': '(JS) Broken Image: ' + imagePath, 'exFatal': false});
            nebula.nv('event', 'Broken Image');
        }
    });
};

Override

To override or disable this JavaScript function, simply redeclare it with the exact same function name.

JavaScript
nebula.errorMitigation = function(){
    //Write your own code here, leave it blank, or return false.
}