mattpolito (owner)

Fork Of

gist: 165920 by jnunemaker Pretty output of rails erro...

Revisions

gist: 166010 Download_button fork
public
Public Clone URL: git://gist.github.com/166010.git
Embed All Files: show embed
application.js #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// 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('');
  }
});