PDA

View Full Version : UX.ErrorHandler



harley.333
6 May 2011, 5:54 AM
Attached is UX.ErrorHandler class (this replaces my Ext.ux.ErrorHandler class for Ext3).

I removed the "Ext" namespace so the dynamic loader will work as expected:

Ext.Loader.setConfig({
enabled: true,
paths: {
"APP": "myApp",
"UX": "js/libs/ux",
"Ext": "ext/resources/src"
}
});
Ext.require("UX.ErrorHandler");
Other than that, the class itself is largely unchanged.

Usage:

//1. Setup Global Error Handler
UX.ErrorHandler.init();
UX.ErrorHandler.on("error", function (err) {
// build some user-friendly text
// display the text to the user
// log to the server
});

//2. Setup Ext Error Handler
Ext.Error.handle = UX.ErrorHandler.handleError;
The following code has nothing to do with UX.ErrorHandler. But it demonstrates how I handle server-side exceptions within Ext in a single location.

//3. Setup Server-Connection Error Handler
Ext.util.Observable.observe(Ext.data.Connection, {
requestcomplete: function (conn, response, options) {
if (options.isUpload && response.responseText.indexOf("{errors:") == 0) {
// build some user-friendly text
// display the text to the user
}
},
requestexception: function (conn, response, options) {
// build some user-friendly text
// display the text to the user
}
});