1
YUI.add('util-oops', function (Y, NAME) {
4
Y.namespace('U1.util');
6
var Oops = Y.Base.create('oneUtilOops', Y.Base, [], {
8
initializer: function (config) {
10
config = config || {};
12
var globalContext = config.globalContext || this.get('globalContext'),
13
globalHandler = config.globalErrorHandler || this._globalErrorHandler;
16
// replace with our handler
17
this._oldOnError = globalContext.onerror;
18
globalContext.onerror = Y.bind(globalHandler, this);
22
destructor: function () {
24
// revert global error handler
25
this.get('globalContext').onerror = this._oldOnError;
29
// overloaded to handle directly calling window.onerror(new Error("Foo"))
30
_globalErrorHandler: function (message, url, line) {
33
if(Y.Lang.isObject(message)) {
43
// send returns supress
44
return this.send(error);
47
_createOopsReport: function (error) {
49
return new Y.U1.util.OopsReport(error, {
50
ioConfig: this.get('ioConfig'),
51
endPoint: this.get('endPoint'),
52
reporter: this.get('reporter'),
53
sessionData: this.get('sessionData')
58
// creates OOPS report and sends it
59
send: function (error) {
61
var report = this._createOopsReport(error);
65
this.fire('registered');
71
return this.get('suppress');
76
globalErrorHandler: { value: null },
77
globalContext: { value: Y.config.win },
86
reporter: { value: 'u1.' + Y.config.win.location.hostname },
87
sessionData: { value: null },
88
suppress: { value: false },
96
OopsReport = function (error, config) {
103
this.config = config;
109
OopsReport.prototype = {
113
initializer: function () {
115
this._io = new Y.IO();
121
return this._io.send(this.config.endPoint, Y.merge(this.config.ioConfig, {
122
data: this._createReport()
127
_createReport: function () {
129
var reportElements = [
130
{ reporter: this.config.reporter },
132
this.config.sessionData,
133
this._normalizeError(this.error)
137
j = reportElements.length;
139
// Will try to report all reportElements
140
// If it fails, drop one element at a time
141
// This will end up with just the basic error
143
// e.g. if reporter, ua and sessiondata are all borked,
144
// the report will still include the error
148
ret = Y.JSON.stringify(Y.merge.apply(this, reportElements.splice(i)));
151
// report the stringification failure
152
// but drop everything but the error
153
new Y.U1.util.OopsReport(e, {
154
endPoint: this.config.endPoint,
155
ioConfig: this.config.ioConfig
159
if(Y.Lang.isString(ret)) {
170
_normalizeError: function (error) {
174
{ accepts: ['message', 'description'], output: 'message' },
175
{ accepts: ['url', 'fileName'], output: 'url' },
176
{ accepts: ['line', 'lineNumber'], output: 'line' },
177
{ accepts: ['column', 'columnNumber'], output: 'column' },
178
{ accepts: ['name'], output: 'name' },
179
{ accepts: ['number'], output: 'errorCode' },
180
{ accepts: ['stack', 'stacktrace'], output: 'stacktrace' }
183
// take accepted inputs and add as output on e
184
Y.each(props, function (prop) {
185
Y.each(prop.accepts, function (accept) {
187
e[prop.output] = error[accept];
195
uaToJSON: function () {
198
Y.each(Y.UA, function(v, k) {
199
if (!Y.Lang.isFunction(v)) {
203
if(Y.Lang.isNumber(v)) {
204
queryObj.browser = k;
205
queryObj.browserVersion = v;
218
Y.U1.util.Oops = Oops;
219
Y.U1.util.OopsReport = OopsReport;
222
}, '@VERSION@', {"requires": ["base", "io-base", "json-stringify"]});