Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6602609
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:53:48+00:00 2026-05-25T18:53:48+00:00

I’m building upon RESTFul Store example of ExtJs 4. I’d like my script to

  • 0

I’m building upon RESTFul Store example of ExtJs 4. I’d like my script to display errors provided by the REST server, when either Add or Delete request fails. I’ve managed to obtain the success status of a request (see the code below), but how do I reach the message provided with the response?

Store:

    var store = Ext.create('Ext.data.Store', {
    model: 'Users',
    autoLoad: true,
    autoSync: true,
    proxy: {
        type: 'rest',
        url: 'test.php',
        reader: {
            type: 'json',
            root: 'data',
            model: 'Users'
        },
        writer: {
            type: 'json'
        },
        afterRequest: function(request, success) {
            console.log(success); // either true or false
        },
        listeners: { 
            exception: function(proxy, response, options) {

                // response contains responseText, which has the message
                // but in unparsed Json (see below) - so I think 
                // there should be a better way to reach it than 
                // parse it myself

                console.log(proxy, response, options); 
            }
        }
    }
});

Typical REST response:

"{"success":false,"data":"","message":"VERBOSE ERROR"}"

Perhaps I’m doing it all wrong, so any advice is appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T18:53:49+00:00Added an answer on May 25, 2026 at 6:53 pm

    I assume that your service follows the REST principle and uses HTTP status codes other than 2xx for unsuccessful operations.
    However, Ext will not parse the response body for responses that do not return status OK 2xx.
    What the exception/response object (that is passed to ‘exception’ event listeners) does provide in such cases is only the HTTP status message in response.statusText.

    Therefore you will have to parse the responseText to JSON yourself. Which is not really a problem since it can be accomplished with a single line.

    var data = Ext.decode(response.responseText);
    

    Depending on your coding style you might also want to add some error handling and/or distinguish between ‘expected’ and ‘unexpected’ HTTP error status codes. (This is from Ext.data.reader.Json)

    getResponseData: function(response) {
        try {
            var data = Ext.decode(response.responseText);
        }
        catch (ex) {
            Ext.Error.raise({
                response: response,
                json: response.responseText,
                parseError: ex,
                msg: 'Unable to parse the JSON returned by the server: ' + ex.toString()
            });
        }
    
        return data;
    },
    

    The reason for this behavior is probably because of the REST proxy class not being a first class member in the data package. It is derived from a common base class that also defines the behavior for the standard AJAX (or JsonP) proxy which use HTTP status codes only for communication channel errors. Hence they don’t expect any parsable message from the server in such cases.
    Server responses indicating application errors are instead expected to be returned with HTTP status OK, and a JSON response as posted in your question (with success:"false" and message:"[your error message]").

    Interestingly, a REST server could return a response with a non-2xx status and a response body with a valid JSON response (in Ext terms) and the success property set to ‘true’. The exception event would still be fired and the response body not parsed.
    This setup doesn’t make a lot of sense – I just want to point out the difference between ‘success’ in terms of HTTP status code compared to the success property in the body (with the first having precedence over the latter).

    Update

    For a more transparent solution you could extend (or override) Ext.data.proxy.Rest: this will change the success value from false to true and then call the standard processResponse implementation. This will emulate ‘standard’ Ext behavior and parse the responseText. Of course this will expect a standard JSON response as outlined in your original post with success:"false" (or otherwise fail).
    This is untested though, and the if expression should probably be smarter.

    Ext.define('Ext.ux.data.proxy.Rest', {
        extend: 'Ext.data.proxy.Rest',
    
        processResponse: function(success, operation, request, response, callback, scope){
            if(!success && typeof response.responseText === 'string') { // we could do a regex match here
                var args = Array.prototype.slice.call(arguments);
                args[0] = true;
                this.callParent(args);
            } else {
                this.callParent(arguments);
            }
        }
    })
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I've got a string that has curly quotes in it. I'd like to replace
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
i want to parse a xhtml file and display in UITableView. what is the
In my XML file chapters tag has more chapter tag.i need to display chapters

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.