check what is being written to our log files.
[Pman.Core] / Pman.OnJavascriptError.js
1 /**
2  *
3  * Window onerror handler..  reports to our logger.
4  *
5  */
6
7 Pman.OnJavascriptError = {
8     
9     init : function()
10     {
11         this.history = [];
12         window.onerror = this.handler.createDelegate(this);
13         
14     },
15     
16     history  : false, // array of previous events...
17     
18     lock : false,
19     
20     handler : function(msg, url, line, col, errorObj)
21     {
22         
23         if (this.lock) {
24             return false;
25         }
26         
27         // note - some are not passed by all browsers.
28         col = col || -1;
29         var stack = errorObj ? errorObj.stack : false;
30         
31         
32         
33         
34         if (!errorObj) {
35             var stack = [];
36             var f = arguments.callee.caller;
37             while (f) {
38                 stack.push(f.name);
39                 f = f.caller;
40             }
41         }
42         // 10 events max in 5 minutes
43         var last = this.history.length  > 10 ? this.history.shift() : false;
44         if (last && last > (new Date()).add( Date.MINUTE, -5)) {
45             this.history.unshift(last); // put it back on, and ingore this error.
46             return false;
47         }
48         
49         this.history.push(new Date());
50         
51         
52         // rate limit...
53         this.lock = true;
54         
55         
56         
57         new Pman.Request({
58             url : baseURL + '/Core/JavascriptError',
59             method  : 'POST',
60             params : {
61                 msg : msg,
62                 url : url,
63                 source_url : window.location.toString(),
64                 line : line,
65                 col : col,
66                 stack : '' + stack // array??? 
67             },
68             success : this.resetLock,
69             failure : this.resetLock
70                 
71             
72         });
73         return false;
74         
75     
76     
77     
78     },
79     resetLock : function()
80     {
81         Pman.OnJavascriptError.lock = false;
82     }
83     
84 };
85 Pman.OnJavascriptError.init();