-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathErrorHandler.js
More file actions
402 lines (375 loc) · 15 KB
/
ErrorHandler.js
File metadata and controls
402 lines (375 loc) · 15 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
/*******************************************************************************
* Copyright (c) 2011, 2023 EclipseSource and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* EclipseSource - initial API and implementation
******************************************************************************/
/*global console: false */
rwt.qx.Class.define( "rwt.runtime.ErrorHandler", {
statics : {
_overlay : null,
_box : null,
processJavaScriptErrorInResponse : function( script, error, currentRequest ) {
var content = this._getErrorPageHeader();
content += "<pre>" + this._gatherErrorDetails( error, script, currentRequest ) + "</pre>";
this.showErrorBox( "client error", true, content );
},
processJavaScriptError : function( error ) {
this.errorObject = error; // for later inspection by developer
if( typeof console === "object" ) {
var msg = "Error: " + ( error.message ? error.message : error );
if( typeof console.error !== "undefined" ) { // IE returns "object" for typeof
console.error( msg );
} else if( typeof console.log !== "undefined" ) {
console.log( msg );
}
if( typeof console.log === "function" && error.stack ) {
console.log( "Error stack:\n" + error.stack );
} else if( typeof console.trace !== "undefined" ) {
console.trace();
}
}
var debug = true;
try {
debug = rwt.util.Variant.isSet( "qx.debug", "on" );
} catch( ex ) {
// ignore: Variant may not be loaded yet
}
if( debug ) {
var content = this._getErrorPageHeader();
content += "<pre>" + this._gatherErrorDetails( error ) + "</pre>";
this.showErrorBox( "client error", true, content );
throw error;
}
},
showErrorPage : function( content ) {
this._enableTextSelection();
this._freezeApplication();
document.title = "Error Page";
this._createErrorPageArea().innerHTML = content;
},
showErrorBox : function( errorType, freeze, errorDetails ) {
if( freeze ) {
this._freezeApplication();
}
if( errorType !== "connection error" ) {
this._unloadAllIframes();
}
this._overlay = this._createOverlay();
this._box = this._createErrorBoxArea( 450, 150 );
var themeStore = rwt.theme.ThemeStore.getInstance();
var border = themeStore.getBorder( "ErrorBox", {}, "border" );
border.renderElement( this._box );
this._box.style.padding = "0px";
this._box.style.overflow = "hidden";
var errorBoxData = this._getErrorBoxData( errorType );
this._title = this._createErrorBoxTitleArea( this._box );
this._title.innerHTML = errorBoxData.title;
this._description = this._createErrorBoxDescriptionArea( this._box );
this._description.innerHTML = errorBoxData.description;
this._action = this._createErrorBoxActionArea( this._box );
var actions = errorBoxData.action;
if( errorDetails && errorDetails.trim().length > 0 ) {
actions += this._getDetailsAction();
}
if( actions ) {
this._action.innerHTML = actions;
}
var hyperlink = this._action.getElementsByTagName( "a" )[ 0 ];
if( hyperlink ) {
this._styleHyperlinkAsButton( hyperlink );
hyperlink.focus();
}
var retryHyperlink = document.getElementById( "rwt_retryActionHyperlink" );
if( retryHyperlink ) {
retryHyperlink.addEventListener( "click", function( event ) {
event.preventDefault();
rwt.remote.Connection.getInstance()._retry();
return false;
} );
}
var detailsHyperlink = document.getElementById( "rwt_detailsActionHyperlink" );
if( detailsHyperlink ) {
this._styleHyperlinkAsButton( detailsHyperlink );
var self = this;
detailsHyperlink.addEventListener( "click", function() { self.showErrorPage( errorDetails ); } );
}
},
_getDetailsAction : function() {
var detailsMessage = rwt.client.ClientMessages.getInstance().getMessage( "Details" );
return "<a id=\"rwt_detailsActionHyperlink\" href=\"javascript:void(0)\">" + detailsMessage + "</a>";
},
showWaitHint : function() {
if (this._overlay === null) {
this._overlay = this._createOverlay();
}
var themeStore = rwt.theme.ThemeStore.getInstance();
var cssElement = "SystemMessage-DisplayOverlay";
var icon = themeStore.getSizedImage( cssElement, {}, "background-image" );
if( this._box === null && icon && icon[ 0 ] ) {
this._box = this._createErrorBoxArea( icon[ 1 ], icon[ 2 ] );
rwt.html.Style.setBackgroundImage( this._box, icon[ 0 ] );
this._box.style.backgroundColor = "transparent";
this._box.style.border = "none";
this._box.style.overflow = "hidden";
}
},
hideErrorBox : function() {
if( this._box ) {
this._box.parentNode.removeChild( this._box );
this._box = null;
}
if( this._overlay ) {
this._overlay.parentNode.removeChild( this._overlay );
this._overlay = null;
}
rwt.event.EventHandler.setBlockKeyEvents( false );
},
_getErrorPageHeader : function() {
var errorBoxData = this._getErrorBoxData( "client error" );
var result = "<h2>" + errorBoxData.title + "</h2>";
result += "<h3>" + errorBoxData.details + "</h3>";
result += "<hr/>";
return result;
},
_gatherErrorDetails : function( error, script, currentRequest ) {
var info = [];
try {
info.push( "Error: " + error + "\n" );
if( script ) {
info.push( "Script: " + script );
}
if( error instanceof Error ) {
for( var key in error ) { // NOTE : does not work in webkit (no iteration)
info.push( key + ": " + error[ key ] );
}
if( error.stack ) { // ensures stack is printed in webkit, might be printed twice in gecko
info.push( "Stack: " + error.stack );
}
}
info.push( "Debug: " + rwt.util.Variant.get( "qx.debug" ) );
if( currentRequest ) {
info.push( "Request: " + currentRequest.getData() );
}
var inFlush = rwt.widgets.base.Widget._inFlushGlobalQueues;
if( inFlush ) {
info.push( "Phase: " + rwt.widgets.base.Widget._flushGlobalQueuesPhase );
}
} catch( ex ) {
// ensure we get a info no matter what
}
return info.join( "\n " );
},
_createOverlay : function() {
var element = document.createElement( "div" );
var themeStore = rwt.theme.ThemeStore.getInstance();
var color = themeStore.getColor( "SystemMessage-DisplayOverlay", {}, "background-color" );
var alpha = themeStore.getAlpha( "SystemMessage-DisplayOverlay", {}, "background-color" );
var style = element.style;
style.position = "fixed";
style.width = "100%";
style.height = "100%";
style.backgroundColor = color === "undefined" ? "transparent" : color;
style.opacity = alpha;
style.zIndex = 100000000;
document.body.appendChild( element );
rwt.event.EventHandler.setBlockKeyEvents( true );
return element;
},
_createErrorPageArea : function() {
var element = document.createElement( "div" );
var style = element.style;
style.position = "absolute";
style.width = "100%";
style.height = "100%";
style.backgroundColor = "#ffffff";
style.zIndex = 100000001;
style.overflow = "auto";
style.padding = "10px";
document.body.appendChild( element );
return element;
},
_createErrorBoxArea : function( width, height ) {
var element = document.createElement( "div" );
var style = element.style;
style.position = "fixed";
style.width = width + "px";
style.height = height + "px";
var doc = rwt.widgets.base.ClientDocument.getInstance();
var left = ( doc.getClientWidth() - width ) / 2;
var top = ( doc.getClientHeight() - height ) / 2;
style.left = ( left < 0 ? 0 : left ) + "px";
style.top = ( top < 0 ? 0 : top ) + "px";
style.zIndex = 100000001;
style.padding = "10px";
style.textAlign = "center";
style.fontFamily = 'verdana,"lucida sans",arial,helvetica,sans-serif';
style.fontSize = "12px";
style.fontStyle = "normal";
style.fontWeight = "normal";
document.body.appendChild( element );
return element;
},
_createErrorBoxTitleArea : function( parentElement ) {
var element = document.createElement( "div" );
var themeStore = rwt.theme.ThemeStore.getInstance();
var cssElement = "ErrorBox-Titlebar";
var color = themeStore.getColor( cssElement, {}, "color" );
var font = themeStore.getFont( cssElement, {}, "font" );
var backgroundColor = themeStore.getColor( cssElement, {}, "background-color" );
var style = element.style;
style.position = "absolute";
style.left = "0px";
style.top = "0px";
style.width = "100%";
style.height = "40px";
style.padding = "10px";
style.textAlign = "left";
style.color = color;
style.font = font.toCss();
style.backgroundColor = backgroundColor;
parentElement.appendChild( element );
return element;
},
_createErrorBoxDescriptionArea : function( parentElement ) {
var element = document.createElement( "div" );
var themeStore = rwt.theme.ThemeStore.getInstance();
var cssElement = "ErrorBox";
var color = themeStore.getColor( cssElement, {}, "color" );
var font = themeStore.getFont( cssElement, {}, "font" );
var backgroundColor = themeStore.getColor( cssElement, {}, "background-color" );
var style = element.style;
style.position = "absolute";
style.left = "0px";
style.top = "40px";
style.width = "100%";
style.height = "70px";
style.padding = "10px";
style.overflow = "auto";
style.textAlign = "left";
style.font = font.toCss();
style.color = color;
style.backgroundColor = backgroundColor;
parentElement.appendChild( element );
return element;
},
_createErrorBoxActionArea : function( parentElement ) {
var element = document.createElement( "div" );
var style = element.style;
style.position = "absolute";
style.left = "0px";
style.top = "110px";
style.width = "100%";
style.height = "40px";
style.padding = "10px";
style.textAlign = "center";
style.borderTop = "1px solid #CCCCCC";
style.backgroundColor = "#F2F2F2";
style.fontSize = "14px";
parentElement.appendChild( element );
return element;
},
_freezeApplication : function() {
try {
var display = rwt.widgets.Display.getCurrent();
display.setExitConfirmation( null );
//qx.io.remote.RequestQueue.getInstance().setEnabled( false );
rwt.event.EventHandler.detachEvents();
rwt.qx.Target.prototype.dispatchEvent = function() {};
rwt.animation.Animation._stopLoop();
} catch( ex ) {
try {
console.log( "_freezeApplication exception: " + ex );
} catch( exTwo ) {
// ignore
}
}
},
_unloadAllIframes : function() {
var iframes = document.getElementsByTagName( "iframe" );
for( var i = 0; i < iframes.length; i++ ) {
iframes[ i ].src = rwt.remote.Connection.RESOURCE_PATH + "static/html/blank.html";
}
},
_enableTextSelection : function() {
var doc = rwt.widgets.base.ClientDocument.getInstance();
doc.setSelectable( true );
if( rwt.client.Client.isGecko() ) {
var EventHandlerUtil = rwt.event.EventHandlerUtil;
document.documentElement.removeEventListener( "mousedown",
EventHandlerUtil._ffMouseFixListener,
false );
}
},
_getErrorBoxData : function( errorType ) {
var result = {
title : "",
description : "",
details : "",
action : ""
};
var messages = rwt.client.ClientMessages.getInstance();
switch( errorType ) {
case "invalid request counter":
case "request failed":
result.title = messages.getMessage( "ServerError" );
result.description = messages.getMessage( "ServerErrorDescription" );
result.action = "<a href=\"" + this._getRestartURL() + "\">"
+ messages.getMessage( "Restart" ) + "</a>";
break;
case "session timeout":
result.title = messages.getMessage( "SessionTimeout" );
result.description = messages.getMessage( "SessionTimeoutDescription" );
result.action = "<a href=\"" + this._getRestartURL() + "\">"
+ messages.getMessage( "Restart" ) + "</a>";
break;
case "connection error":
result.title = messages.getMessage( "ConnectionError" );
result.description = messages.getMessage( "ConnectionErrorDescription" );
result.action = "<a id=\"rwt_retryActionHyperlink\" href=\"#\">"
+ messages.getMessage( "Retry" ) + "</a>";
break;
case "client error":
result.title = messages.getMessage( "ClientError" );
result.description = messages.getMessage( "ClientErrorDescription" );
result.details = messages.getMessage( "Details" );
result.action = "<a href=\"" + this._getRestartURL() + "\">"
+ messages.getMessage( "Restart" ) + "</a>";
break;
default:
result.title = messages.getMessage( "ServerError" );
result.description = messages.getMessage( "ServerErrorDescription" );
result.action = "<a href=\"" + this._getRestartURL() + "\">"
+ messages.getMessage( "Restart" ) + "</a>";
}
result.title = rwt.util.Encoding.replaceNewLines( result.title, "" );
result.description = rwt.util.Encoding.replaceNewLines( result.description, "<br/>" );
return result;
},
_getRestartURL : function() {
var result = String( window.location );
var index = result.indexOf( "#" );
if( index != -1 ) {
result = result.substring( 0, index );
}
return result;
},
_styleHyperlinkAsButton : function( element ) {
var style = element.style;
style.outline = "none";
style.textDecoration = "none";
style.backgroundColor = "#E8E8E8";
style.color = "#4a4a4a";
style.padding = "5px 15px";
style.margin = "5px";
style.borderTop = "1px solid #CCCCCC";
style.borderRight = "1px solid #333333";
style.borderBottom = "1px solid #333333";
style.borderLeft = "1px solid #CCCCCC";
}
}
} );