[CLOSED] Handle errors when loading store´s data

  1. #1

    [CLOSED] Handle errors when loading store´s data

    The following example throws an exception when Store is loading. I would like to know the correct way to handle the error for avoiding "Internal Server Error" exception.

    I have some questions about the process of loading store´s data
    1. In version 2.0 the listener LoadException of the store was removed and there is just the Exception listener, is it correct?
    2. why can´t i set the Success and ErrorMessages of properties of the StoreResult (StoreResponseData)?
    3. I would also like to know which is the correct way to handle an exception when loading the store´s data.
    4. Do i have to implement a custom class to accomplish it?


    <ext:GridPanel ID="GridPanel1" runat="server" Width="700" Height="500" Title="ExtJS.com - Browse Forums">
        <Store>
            <ext:Store ID="Store1" runat="server" PageSize="30" RemoteSort="true" AutoLoad="true">
                <Proxy>
                    <ext:AjaxProxy Url="/Example/Test/">
                        <Reader>
                            <ext:JsonReader Root="data" TotalProperty="total" />
                        </Reader>
                    </ext:AjaxProxy>
                </Proxy>
                <Model>
                    <ext:Model ID="Model1" runat="server">
                        <Fields>
                            <ext:ModelField Name="ID" />
                            <ext:ModelField Name="Name" />
                        </Fields>
                    </ext:Model>
                </Model>
                <Listeners>
                    <Exception Handler="alert('error')" />
                </Listeners>
            </ext:Store>
        </Store>
        <ColumnModel ID="ColumnModel1" runat="server">
            <Columns>
                <ext:Column ID="Column1" runat="server" Text="ID" DataIndex="ID" />
                <ext:Column ID="Column2" runat="server" Text="Name" DataIndex="Name" />
            </Columns>
        </ColumnModel>
        <View>
            <ext:GridView ID="GridView1" runat="server" TrackOver="false" LoadMask="true">
            </ext:GridView>
        </View>
        <BottomBar>
            <ext:PagingToolbar runat="server" />
        </BottomBar>
    </ext:GridPanel>
    
    public StoreResult Test(int start, int limit)
    {
        throw new Exception("Message");
    
        StoreResult response = new StoreResult();
    
        List<Person> data = new List<Person>();
    
        Random randow = new Random();
        DateTime now = DateTime.Now;
    
        for (int i = start + 1; i <= start + limit; i++)
        {
            Person p = new Person()
            {
                ID = i,
                Name = "name " + i,
            };
    
            data.Add(p);
        }
    
        response.Data = data;
        response.Total = 50000;
    
        return response;
    }
    Last edited by Daniil; May 07, 2012 at 3:14 PM. Reason: [CLOSED]
  2. #2
    Hi,

    Quote Originally Posted by RCN View Post
    1. In version 2.0 the listener LoadException of the store was removed and there is just the Exception listener, is it correct?
    LoadException is already deprecated in ExtJS 3.4. So, it has been just removed in ExtJS 4.

    Yes, please use Exception. By the way, Store Exception is relayed from its proxy. So, you can use proxy Exception as well.

    Quote Originally Posted by RCN View Post
    2. why can´t i set the Success and ErrorMessages of properties of the StoreResult (StoreResponseData)?
    Thanks for the report. We will add.

    Quote Originally Posted by RCN View Post
    3. I would also like to know which is the correct way to handle an exception when loading the store´s data.
    Please use set up Exception handler of Store or its proxy.

    Quote Originally Posted by RCN View Post
    4. Do i have to implement a custom class to accomplish it?
    I don't think you need to implement a custom class since we will add Success and ErrorMessage for the StoreResult class.
  3. #3
    2. why can´t i set the Success and ErrorMessages of properties of the StoreResult (StoreResponseData)?
    is there any estimate of when this problem will be solved?
  4. #4
    We forgot to notice you, the Success and Message properties have been added April'13.

    Though, I think there is a bug in ExtJS which I've reported here:
    http://www.sencha.com/forum/showthread.php?201005

    Here is the example how get it working for now. Please see the comments.

    I will monitor it and notice you when ExtJS or we will come up with the permanent fix.

    Example View
    <%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Ext.Net.MVC v2 Example</title>
    
        <ext:ResourcePlaceHolder runat="server" Mode="ScriptFiles" />
    
        <%--This is a temporary fix--%>
        <script type="text/javascript">
            Ext.data.AbstractStore.override({
                onProxyException : function (proxy, response, operation) {
                    var error = operation.getError(),
                        message;
                        
                    if (!Ext.isDefined(error)) {
                        error = Ext.decode(response.responseText).message;
                    } 
                    
                    message = Ext.isString(error) ? error : ("(" + error.status + ")" + error.statusText);
    
                    this.fireEvent("exception", proxy, response, operation);
                
                    if (Ext.net.DirectEvent.fireEvent("ajaxrequestexception", response, { "errorMessage": message }, null, null, null, null, operation) !== false) {
                        if (this.showWarningOnFailure !== false) {
                            Ext.net.DirectEvent.showFailure(response, response.responseText);
                        }
                    }
                }
            });
        </script>
    </head>
    <body>
        <ext:ResourceManager runat="server" />
        
        <ext:Store runat="server" ShowWarningOnFailure="false">
            <Model>
                <ext:Model runat="server" />
            </Model>
            <Proxy>
                <ext:AjaxProxy Url="/Test/GetData">
                    <Listeners>
                        <Exception Handler="var msg = Ext.decode(response.responseText).message; //when it will be fixed you will be able to use just operation.getError()
                                            alert(msg);" />
                    </Listeners>
                </ext:AjaxProxy>
            </Proxy>
        </ext:Store>
    </body>
    </html>
    Example Controller Action
    public ActionResult GetData()
    {
        StoreResult r = new StoreResult();
        r.Message = "Hello! I am the Error.";
        r.Success = false;
    
        return r;
    }
  5. #5
    There was an update within the thread.
    http://www.sencha.com/forum/showthre...l=1#post796241

    So, you have to set up
    <ext:JsonReader MessageProperty="message" ReadRecordsOnFailure="false" />
    See also
    http://docs.sencha.com/ext-js/4-1/#!...essageProperty
    http://docs.sencha.com/ext-js/4-1/#!...cordsOnFailure

Similar Threads

  1. [CLOSED] Delay loading of data
    By cwolcott in forum 2.x Legacy Premium Help
    Replies: 8
    Last Post: Aug 08, 2012, 4:20 PM
  2. [CLOSED] Trigger the loading of TreePanel´s data
    By RCN in forum 2.x Legacy Premium Help
    Replies: 6
    Last Post: May 18, 2012, 5:00 PM
  3. Replies: 2
    Last Post: Apr 24, 2011, 9:14 PM
  4. [CLOSED] GridPanel Loading with Large Data Set
    By bethc in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Oct 28, 2009, 2:20 PM
  5. [CLOSED] Combobox not loading data
    By tdracz in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: Sep 22, 2009, 6:45 AM

Posting Permissions