ErrorBoard
ErrorBoard copied to clipboard
why cannot catch ajax error, net error ?
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
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?