View Full Version : Exception / Error Handling for Model?

6 Mar 2011, 7:11 PM
I am new to ExtJs and version 4.0 and I am totally clueless how to do proper exception handling in the new Model!

I see the "successProperty" in the documentation for the Ext.data.reader. The default is "success". Ok that's good to know. Then in the docs it says "see Ext.data.Proxy.exception"... I click it and I did not "see" anything related to exceptions. I am on pre-release 3 of version 4.0. This is the documentation I am referring to in the distribution / zip file:


So my first question is how to handle a problem / exception on the server. I am using MVC ASP.NET... When exceptions are thrown server-side I get an error 500. I can override this and return any code I want other than 200. Also, I can make sure that it returns JSON rather than a error.aspx.

I placed "success" as a property in my model and also did this in JS:

Ext.onReady(function () {
Ext.get('mb1').on('click', function (e) {
success: function (user) {

var i = 1;

failure: function (something)
var i = 1;

On the server side I set success to false... I did not hit my failure function (see above code). I also tried just throwing a .NET exception on the server (creates a 500 and returns a error.aspx type page). Either case I am not hitting the failure method. I placed successProperty in my reader for my proxy definition on my model. I set it to the default just in case (success)... I tried various incantations and derivations and yet I still can't get anything to fire in ExtJS to show the error.

Here is my current model:

fields: [
{ name: 'LoginUserId', type: 'string' },
{ name: 'FirstName', type: 'string' },
{ name: 'LastName', type: 'string' },
{ name: 'IsNew', type: 'boolean' },
{ name: 'IsDirty', type: 'boolean' },
{ name: 'IsDeleted', type: 'boolean' },
{ name: 'success'}],
type: 'rest',
url: '/Home/Index2/',
type: 'json',
successProperty: 'success'

So first, what am I doing wrong? It's hard for me to even know due to fairly sparse documentation.

Second I expect, because of "sucessProperty" being defined in the reader, I would not need to create a "success" definition, in my fields definition, on my model. Is that correct (I tried both ways)?

I think what I would ideally want is trap the exception on the server and send some sort of JSON response saying there was an exception and what the message was. I would rather not have this defined as part of my model on the JavaScript side of the house. To me it should be something that is "thrown" on the server and then the extjs model just gets something like this:

success: false,
message: "You forgot to pay your electric bill"

Maybe it works that way and I am just floundering... I don't know. Hard to know... My second question is on client-side exceptions in general... Things like dropped Internet connection, null fields, divide by zero, etc. I might post a separate thread later as I am more interested in the model at the moment. I have come a long way and now I need some robust error handling on my model (not validation handling) But if you have pearls of wisdom for exception handling in general, as well, please share!


8 Mar 2011, 5:51 AM
I think that I was bumping into this error (I did get that error several times as I was monkeying around with things to try, I just did not know enough to know it was a bug):


I am still not quite sure if I am doing things right or not as the documentation is fairly vague. If someone has some sample code of how I should handle servers errors that would be awesome. Obviously, the code might not work until the above bug is fixed.