Thank you for reporting this bug. We will make it our priority to review this report.
  1. #1
    Sencha User
    Join Date
    Jun 2008
    Posts
    314
    Vote Rating
    18
    Qtx will become famous soon enough Qtx will become famous soon enough

      0  

    Default Behavior of the form actions 'Load' and 'Submit' in the case of JSON parse error

    Behavior of the form actions 'Load' and 'Submit' in the case of JSON parse error


    These two actions have some error handling in the onSuccess method, many types of errors are caught up and correctly reported for the further processing.

    But if the response data format is damaged because of a program warning or other cause, the processing stops completely because of the JSON parse error.

    Since the ExtJS version 3.x, I am overriding the onSuccess method of the Ext.form.action.Load and Ext.form.action.Submit, to correctly catch up the JSON parse error. Now, I would like to offer to take this in to the standard functionality.

    Original code:

    Code:
    Ext.override(Ext.form.action.Load, {
        
        onSuccess: function(response){
            var result = this.processResponse(response),
                form = this.form;
            if (result === true || !result.success || !result.data) {
                this.failureType = Ext.form.action.Action.LOAD_FAILURE;
                form.afterAction(this, false);
                return;
            }
            form.clearInvalid();
            form.setValues(result.data);
            form.afterAction(this, true);
        },
        
    }); // Ext.form.action.Load
    Adjusted code:

    Code:
    /*
    The reason of the override is that the parse error is not handled.
    If the response JSON data is invalid, the processing stops completely
    because of the JSON parse error.
    We take the call processResponse in the 'try catch', then, we can
    catch up the JSON parse error and correctly report it like other errors.
    */
    
    Ext.override(Ext.form.action.Load, {
    
      onSuccess: function(response){
          var result = false;
          var form = this.form;
    
          try
          {
            result = this.processResponse(response);
          }
          catch(ex)
          {
            this.failureType = 'parse'; // could be Ext.form.action.Action.PARSE_ERROR;
            form.afterAction(this, false);
            return;
          }
    
          if (result !== true || !result.success || !result.data) {
              this.failureType = Ext.form.action.Action.LOAD_FAILURE;
              form.afterAction(this, false);
              return;
          }
          form.clearInvalid();
          form.setValues(result.data);
          form.afterAction(this, true);
      } // onSuccess
    
    }); // Ext.form.action.Load
    Original code:

    Code:
     Ext.override(Ext.form.action.Submit, {
        
        onSuccess: function(response) {
            var form = this.form,
                success = true,
                result = this.processResponse(response);
            if (result !== true && !result.success) {
                if (result.errors) {
                    form.markInvalid(result.errors);
                }
                this.failureType = Ext.form.action.Action.SERVER_INVALID;
                success = false;
            }
            form.afterAction(this, success);
        },
        
    });

    Adjusted code:


    Code:
    /*
    The reason of the override is that the parse error is not handled.
    If the response JSON data is invalid, the processing stops completely
    because of the JSON parse error.
    We take the call processResponse in the 'try catch', then, we can
    catch up the JSON parse error and correctly report it like other errors.
    */
    
    Ext.override(Ext.form.action.Submit, {
    
      onSuccess: function(response) {
          var form = this.form,
              success = true,
              result = false;
    
          try
          {
            result = this.processResponse(response);
          }
          catch(ex)
          {
            this.failureType = 'parse'; // could be Ext.form.action.Action.PARSE_ERROR;
            form.afterAction(this, false);
            return;
          }
    
          if (result !== true && !result.success) {
              if (result.errors) {
                  form.markInvalid(result.errors);
              }
              this.failureType = Ext.form.action.Action.SERVER_INVALID;
              success = false;
          }
          form.afterAction(this, success);
      }, // onSuccess
    
    }); // Ext.form.action.Submit

  2. #2
    Sencha - Support Team
    Join Date
    Feb 2013
    Location
    California
    Posts
    4,081
    Vote Rating
    69
    Gary Schlosberg has a spectacular aura about Gary Schlosberg has a spectacular aura about Gary Schlosberg has a spectacular aura about

      0  

    Default


    Thanks for the report. Moved thread from Ext 5 Bugs forum since you said this was for Ext 3.x. Can you please post a test case which reproduces the issue you are reporting?
    https://fiddle.sencha.com/#home


    Are you a Sencha products veteran who has wondered what it might be like to work at Sencha? If so, please reach out to our recruiting manager:
    sheryl@sencha.com

Thread Participants: 1