Skip to content

Instantly share code, notes, and snippets.

@jnunemaker
Created August 11, 2009 16:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 8 You must be signed in to fork a gist
  • Save jnunemaker/165920 to your computer and use it in GitHub Desktop.
Save jnunemaker/165920 to your computer and use it in GitHub Desktop.
Pretty output of rails errors when doing ajax requests with jQuery
// 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