This project is archived and is in readonly mode.

#442 ✓resolved
Marc Weber

what happens on failure of success() of Request? (eg if JSON.decode fails)

Reported by Marc Weber | October 27th, 2008 @ 01:35 PM | in 2.0 (closed)

a failure can be caused by options.save = false and getting rubbish whenu using Request.JSON etc. (Or maybe there is a case the safe regex doesn't trigger).. In these cases it seems to me that neither onSuccess nor onFailure is triggered which is bad.

So what do you think about passing the error reason to failure so that you can evaluate it and maybe send another request to the server logging the failure? Users usually don't notify you if something doesn't work.. They just click somewhere else.

This patch is untested and only a draft. I'd like to hear some comments how you think about it.

I'd like to propose a patch if we can agree on what behaviour we'd like to have. I'd say: if onSuccess events do fail it's the resposibility of the event to do error handling. But if it does before (eg the JSON decode example) Request.failure() should be called to indicate that.

diff --git a/js/mootools-1.2.1-core-nc.js b/js/mootools-1.2.1-core-nc.js index b70c577..49d41ac 100644 --- a/js/mootools-1.2.1-core-nc.js +++ b/js/mootools-1.2.1-core-nc.js @@ -3679,7 +3679,11 @@ var Request = new Class({

    },

    success: function(text, xml){

  •         this.onSuccess(this.processScripts(text), xml);
    
    
  •         try {
    
    
  •                 this.onSuccess(this.processScripts(text), xml);
    
    
  •         } catch (e) {
    
    
  •                 this.failure(e);
    
    
  •         }
    },
    
    onSuccess: function(){
    
    
    @@ -3687,11 +3691,11 @@ var Request = new Class({
    },
    
    failure: function(){
    
    
  •         this.onFailure();
    
    
  •         this.onFailure.apply(arguments);
    },
    
    onFailure: function(){
    
    
  •         this.fireEvent('complete').fireEvent('failure', this.xhr);
    
    
  •         this.fireEvent('complete').fireEvent('failure', [this.xhr].concat(arguments));
    },
    
    

Comments and changes to this ticket

  • Christoph Pojer

    Christoph Pojer March 13th, 2009 @ 12:42 PM

    • Assigned user changed from “Valerio” to “Christoph Pojer”
  • Christoph Pojer

    Christoph Pojer August 6th, 2009 @ 11:10 PM

    • State changed from “new” to “resolved”

    This feature will be added in MooTools 2.0. Request.JSON will fire an onError event when something is wrong with the JSON. Please note that this is not final and the name of the event may change in the release version.

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

Shared Ticket Bins

People watching this ticket

Pages