ErrorBoard icon indicating copy to clipboard operation
ErrorBoard copied to clipboard

why cannot catch ajax error, net error ?

Open toohamster opened this issue 9 years ago • 1 comments

why cannot catch ajax error, net error ? this my code

window.onerror = function( message, url, line, column, error ) { // var e = encodeURIComponent; // ( new Image() ).src = 'http://127.0.0.1:3000/error?message=' + e( message ) + // '&url=' + e( url ) + // '&line=' + e( line ) + // ( error && error.stack ? '&stack=' + e( error.stack ) : '' ) + // ( column ? '&column=' + e( column ) : '' ); console.warn(message, url, line, column, error); }

$.getJSON( '', {f: 'json', 'asdebug-tag': ''}, function(json){ setContent(json); setTimeout('refresh()',500); } );

if the url cannot load, the brower return 404 net error , but this error cannot catch

toohamster avatar Jan 24 '16 03:01 toohamster

Network or AJAX failures could be logged in ErrorBoard as well, consider doing something like the following:

function reportErrorMessage( message, url, line, column, error ) {
    // This is the function from README
    var e = encodeURIComponent;
    ( new Image() ).src = 'http://127.0.0.1:3000/error?message=' + e( message ) +
    '&url=' + e( url ) +
    '&line=' + e( line ) +
    ( error && error.stack ? '&stack=' + e( error.stack ) : '' ) +
    ( column ? '&column=' + e( column ) : '' );
}

// Catching JavaScript execution errors
window.onerror = reportErrorMessage;

// Catching jQuery AJAX failures
$( document ).ajaxError(function( event, jqxhr, settings, thrownError ) {
    reportErrorMessage( thrownError, settings.url, 0 );
});

Does this work for your case?

Lapple avatar Jan 24 '16 17:01 Lapple