Skip to content

Instantly share code, notes, and snippets.

@galfert
Forked from jnunemaker/application.js
Created August 14, 2009 08:27
Show Gist options
  • Save galfert/167715 to your computer and use it in GitHub Desktop.
Save galfert/167715 to your computer and use it in GitHub Desktop.
// only outputs if console available and does each argument on its own line
function log() {
if (window && window.console && window.console.log) {
var i, len;
for (i=0, len=arguments.length; i<len; i++) {
console.log(arguments[i]);
}
}
}
// Pretty output of rails errors when doing ajax requests with jQuery
$(document).bind('ajaxError', function (event, response, options, error) {
var html, heading, paragraph, pre;
if (response.status == 500) {
html = $(response.responseText);
heading = $(html[1]).text();
paragraph = $(html[3]).text();
pre = $(html[4]).text();
log('');
log('[ERROR] ' + response.status.toString());
log($.trim(heading));
log($.trim(paragraph));
log($.trim(pre));
log('');
} else {
log('');
log('[ERROR] ' + response.status.toString());
log(response.responseText);
log('');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment