Skip to content

Commit 00fccbd

Browse files
committed
first shot at Exceptional for javascript
0 parents  commit 00fccbd

File tree

4 files changed

+66
-0
lines changed

4 files changed

+66
-0
lines changed

Gemfile

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
source 'http://rubygems.org'
2+
3+
gem "rack"
4+
gem "sinatra"
5+
gem "newrelic_rpm"

config.ru

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
require './js.rb'
2+
run Sinatra::Application

js.rb

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
require 'sinatra'
2+
3+
set :public, File.dirname(__FILE__) + '/public'

public/exceptional.js

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
var Exceptional = {
2+
KEY : null,
3+
HOST : 'api.getexceptional.com',
4+
handle: function (msg,url,line) {
5+
if (Exceptional.KEY) {
6+
console.log(document)
7+
var request = document.createElement('iframe');
8+
var protocol_version = 5;
9+
var backtrace_string = 'no backtrace';
10+
request.style.width = '1px';
11+
request.style.height = '1px';
12+
request.style.display = 'none';
13+
var url = 'http://' + Exceptional.HOST + '/api/errors/new?protocol_version=' + protocol_version + '&msg=' + escape(msg) + '&url=' + escape(url) + '&line=' + escape(line) + '&api_key=' + Exceptional.KEY + '&backtrace=' + backtrace_string;
14+
request.src = url;
15+
if (document.body) {
16+
document.body.appendChild(request);
17+
} else{
18+
addLoadEvent(function() {
19+
document.body.appendChild(request);
20+
});
21+
};
22+
23+
} else{
24+
log('Exceptional.KEY is not set!')
25+
};
26+
return true;
27+
},
28+
setKey: function (key) {
29+
Exceptional.KEY = key;
30+
},
31+
setHost: function (host) {
32+
Exceptional.HOST = host;
33+
}
34+
}
35+
36+
window.onerror = function(msg, url, line) {
37+
Exceptional.handle(msg,url,line);
38+
};
39+
40+
// nice way to register the execution of some code when the page has finished loading - from http://simonwillison.net/2004/May/26/addLoadEvent/
41+
function addLoadEvent(func) {
42+
var oldonload = window.onload;
43+
if (typeof window.onload != 'function') {
44+
window.onload = func;
45+
} else {
46+
window.onload = function() {
47+
if (oldonload) {
48+
oldonload();
49+
}
50+
func();
51+
}
52+
}
53+
}
54+
55+
// from Paul Irish : http://paulirish.com/2009/log-a-lightweight-wrapper-for-consolelog/
56+
window.log=function(){log.history=log.history||[];log.history.push(arguments);if(this.console){console.log(Array.prototype.slice.call(arguments))}};

0 commit comments

Comments
 (0)