commit 57898d04ab95c4feebe0dee18073f738e3bbb8d9
parent ab1afde97cf4e4a73333f88ba72c290796c403a5
Author: Felicitus <felicitus@felicitus.org>
Date: Wed, 29 Feb 2012 12:11:01 +0100
Refactored exception dialog to contain request+response data
Diffstat:
5 files changed, 165 insertions(+), 31 deletions(-)
diff --git a/src/frontend/js/Dialogs/ExceptionWindow.js b/src/frontend/js/Dialogs/ExceptionWindow.js
@@ -1,10 +1,15 @@
+/**
+ * Represents an exception window.
+ */
Ext.define('PartKeepr.ExceptionWindow', {
extend: 'Ext.window.Window',
autoScroll: true,
resizable: true,
layout: 'anchor',
width: 500,
- height: 300,
+ //height: 300,
+ autoHeight: true,
+ maxHeight: 800,
cls: Ext.baseCSSPrefix + 'message-box',
initComponent: function () {
@@ -27,13 +32,20 @@ Ext.define('PartKeepr.ExceptionWindow', {
style: 'margin-left: 40px; margin-top: 20px;'
});
- this.exceptionDiv = Ext.create('Ext.Component', { autoEl: { tag: 'div' },
- cls: 'ext-mb-text',
- style: 'overflow: auto'
+ this.exceptionDiv = Ext.create('Ext.form.field.TextArea', {
+ anchor: '100% 100%'
+ });
+
+ this.traceDiv = Ext.create('Ext.form.field.TextArea', {
+ anchor: '100% 100%'
+ });
+
+ this.requestDiv = Ext.create('Ext.form.field.TextArea', {
+ anchor: '100% 100%'
});
- this.traceDiv = Ext.create('Ext.Component', { autoEl: { tag: 'div' },
- cls: 'ext-mb-text'
+ this.responseDiv = Ext.create('Ext.form.field.TextArea', {
+ anchor: '100% 100%'
});
this.exceptionDetails = Ext.create('Ext.form.FieldSet', {
@@ -52,13 +64,29 @@ Ext.define('PartKeepr.ExceptionWindow', {
items: this.traceDiv
});
+ this.requestDetails = Ext.create('Ext.form.FieldSet', {
+ style: 'margin-left: 40px',
+ title: 'Server Request',
+ collapsible: true,
+ collapsed: true,
+ items: this.requestDiv
+ });
+
+ this.responseDetails = Ext.create('Ext.form.FieldSet', {
+ style: 'margin-left: 40px',
+ title: 'Server Response',
+ collapsible: true,
+ collapsed: true,
+ items: this.responseDiv
+ });
+
this.topContainer = Ext.create("Ext.container.Container", {
xtype: 'container',
style: 'padding: 10px',
layout: 'anchor',
anchor: '100% 100%',
items: [this.iconComponent, this.messageDiv, this.detailDiv,
- this.exceptionDetails, this.backtraceDetails]
+ this.exceptionDetails, this.backtraceDetails, this.requestDetails, this.responseDetails]
});
this.items = this.topContainer;
@@ -73,12 +101,16 @@ Ext.define('PartKeepr.ExceptionWindow', {
},
items: [
{ xtype: 'button', text: 'OK', handler: Ext.bind(function () { this.hide(); }, this) }
- //{ xtype: 'button', text: 'Details >>', handler: Ext.bind(function () { this.showDetails(); }, this) }
+ /*{ xtype: 'button', text: 'Details >>', handler: Ext.bind(function () { this.showDetails(); }, this) }*/
]
}];
this.callParent();
},
+ showDetails: function () {
+ this.doComponentLayout();
+ console.log(this.getHeight());
+ },
setIcon : function(icon) {
this.iconComponent.removeCls(this.iconCls);
@@ -91,13 +123,28 @@ Ext.define('PartKeepr.ExceptionWindow', {
this.iconComponent.hide();
}
},
- _showException: function (exception) {
+ /**
+ * Private. Updates the exception dialog with the exception data.
+ *
+ * @see showException
+ *
+ * @param exception The exception data
+ * @param requestData The request data
+ */
+ _showException: function (exception, requestData) {
+ var separator = "==================================";
+
this.setIcon(Ext.MessageBox.ERROR);
this.messageDiv.update(exception.message);
this.setTitle(exception.message);
+ var fullDetails = exception.message;
+
if (exception.detail) {
+ fullDetails += "\n\n"+i18n("Details")+"\n"+separator+"\n";
+ fullDetails += exception.detail;
+
this.detailDiv.update(exception.detail);
} else {
this.detailDiv.update("");
@@ -105,28 +152,69 @@ Ext.define('PartKeepr.ExceptionWindow', {
if (exception.exception) {
- this.exceptionDiv.update(exception.exception);
+ fullDetails += "\n\n"+i18n("Exception")+"\n"+separator+"\n";
+ fullDetails += exception.exception;
+
+ this.exceptionDiv.setValue(exception.exception);
} else {
- this.exceptionDiv.update("No information available");
+ this.exceptionDiv.setValue("No information available");
}
if (exception.backtrace) {
- this.traceDiv.update(nl2br('<code>'+exception.backtrace+'</code>'));
+ fullDetails += "\n\n"+i18n("Backtrace")+"\n"+separator+"\n";
+ fullDetails += exception.exception;
+
+ this.traceDiv.setValue(nl2br(exception.backtrace));
} else {
- this.traceDiv.update("No backtrace available");
+ this.traceDiv.setValue("No backtrace available");
}
- this.show();
+ if (requestData.request) {
+ fullDetails += "\n\n"+i18n("Request")+"\n"+separator+"\n";
+ fullDetails += requestData.request;
+
+ this.requestDiv.setValue(nl2br(requestData.request));
+ } else {
+ this.requestDiv.setValue("No server request information available");
+ }
+ if (requestData.response) {
+ fullDetails += "\n\n"+i18n("Response")+"\n"+separator+"\n";
+ fullDetails += requestData.response;
+
+ this.responseDiv.setValue(nl2br(requestData.response));
+ } else {
+ this.responseDiv.setValue("No server response information available");
+ }
+
+ this.show();
},
statics: {
- showException: function (exception) {
+ /**
+ * Displays the exception window.
+ *
+ * The exception object may contain the following members:
+ * - message: The message to display [mandatory]
+ * - detail: Details about the message [optional]
+ * - exception: Exception details [optional]
+ * - backtrace: The backtrace [optional]
+ *
+ * The request data object may contain the following members:
+ * - request: The request data
+ * - response: The response data
+ *
+ * Any members specified are strings. Any other data type is not supported.
+ *
+ * @param exception The exception object
+ * @param requestData The request data
+ */
+ showException: function (exception, requestData) {
if (!PartKeepr.ExceptionWindow.activeInstance) {
PartKeepr.ExceptionWindow.activeInstance = new PartKeepr.ExceptionWindow();
}
- PartKeepr.ExceptionWindow.activeInstance._showException(exception);
+ PartKeepr.ExceptionWindow.activeInstance._showException(exception, requestData);
}
}
diff --git a/src/frontend/js/ExtJS/Enhancements/Ext.data.reader.Json-exceptionHandling.js b/src/frontend/js/ExtJS/Enhancements/Ext.data.reader.Json-exceptionHandling.js
@@ -0,0 +1,22 @@
+Ext.override(Ext.data.reader.Json, {
+ getResponseData: function(response) {
+ var data;
+ try {
+ data = Ext.decode(response.responseText);
+ }
+ catch (ex) {
+ var exception = {
+ message: i18n("Critical Error"),
+ detail: i18n("The server returned a response which we were not able to interpret.")
+ };
+
+ var request = {
+ response: response.responseText
+ };
+
+ PartKeepr.ExceptionWindow.showException(exception, request);
+ }
+
+ return data;
+ }
+});+
\ No newline at end of file
diff --git a/src/frontend/js/PartKeepr.js b/src/frontend/js/PartKeepr.js
@@ -472,6 +472,8 @@ Ext.application({
* @return {Object} The RESTProxy definition
*/
PartKeepr.getRESTProxy = function (service) {
+ var request;
+
var obj = {
batchActions: false,
url: PartKeepr.getBasePath()+ '/'+service,
@@ -480,17 +482,23 @@ PartKeepr.getRESTProxy = function (service) {
try {
var data = Ext.decode(response.responseText);
- PartKeepr.ExceptionWindow.showException(data.exception);
+ request = {
+ response: respons.responseText
+ };
+
+ PartKeepr.ExceptionWindow.showException(data.exception, request);
} catch (ex) {
var exception = {
message: i18n("Critical Error"),
- detail: i18n("The server returned a response which we were not able to interpret."),
- exception: "",
- backtrace: response.responseText
+ detail: i18n("The server returned a response which we were not able to interpret.")
};
- PartKeepr.ExceptionWindow.showException(exception);
+ request = {
+ response: response.responseText
+ };
+
+ PartKeepr.ExceptionWindow.showException(exception, request);
}
}
},
diff --git a/src/frontend/js/Util/ServiceCall.js b/src/frontend/js/Util/ServiceCall.js
@@ -70,7 +70,8 @@ Ext.define('PartKeepr.ServiceCall', {
headers: headers
});
},
- onSuccess: function (responseObj) {
+ onSuccess: function (responseObj, options) {
+ console.log(options);
PartKeepr.getApplication().getStatusbar().endLoad();
try {
@@ -78,13 +79,16 @@ Ext.define('PartKeepr.ServiceCall', {
} catch (ex) {
var exception = {
message: i18n("Critical Error"),
- detail: i18n("The server returned a response which we were not able to interpret."),
- exception: "",
- backtrace: responseObj.responseText
+ detail: i18n("The server returned a response which we were not able to interpret.")
};
- PartKeepr.ExceptionWindow.showException(exception);
+ var request = {
+ response: responseObj.responseText,
+ request: Ext.encode(options)
+ };
+
+ PartKeepr.ExceptionWindow.showException(exception, request);
return;
}
@@ -125,20 +129,31 @@ Ext.define('PartKeepr.ServiceCall', {
this.sHandler(response.response);
}
},
- onError: function (response) {
+ onError: function (response, options) {
+ var request;
+
try {
var data = Ext.decode(response.responseText);
- PartKeepr.ExceptionWindow.showException(data.exception);
+ request = {
+ response: response.responseText,
+ request: Ext.encode(options)
+ };
+
+ PartKeepr.ExceptionWindow.showException(data.exception, request);
} catch (ex) {
var exception = {
message: i18n("Critical Error"),
detail: i18n("The server returned a response which we were not able to interpret."),
- exception: "",
backtrace: response.responseText
};
- PartKeepr.ExceptionWindow.showException(exception);
+ request = {
+ response: response.responseText,
+ request: Ext.encode(options)
+ };
+
+ PartKeepr.ExceptionWindow.showException(exception, request);
}
diff --git a/src/setup/js/Cards/ConfigDisplayCard.js b/src/setup/js/Cards/ConfigDisplayCard.js
@@ -15,7 +15,7 @@ Ext.define('PartKeeprSetup.ConfigDisplayCard', {
layout: {
type: 'vbox',
align : 'stretch',
- pack : 'start',
+ pack : 'start'
},
/**