Provide more descriptive ajax error messages
authorColeman Watts <coleman@civicrm.org>
Fri, 12 Dec 2014 01:07:51 +0000 (20:07 -0500)
committerColeman Watts <coleman@civicrm.org>
Fri, 12 Dec 2014 01:07:51 +0000 (20:07 -0500)
js/crm.ajax.js

index 276d02ddfd729d9ebaf9574c37d2baeba7fdd29c..2a48af14607ee529d918a15134237a4644125e0e 100644 (file)
       this.options.url = this.options.url || document.location.href;
       this._originalUrl = this.options.url;
     },
-    _onFailure: function(data) {
+    _onFailure: function(data, status) {
+      var msg, title = ts('Network Error');
       this.options.block && this.element.unblock();
       this.element.trigger('crmAjaxFail', data);
-      CRM.alert(ts('Unable to reach the server. Please refresh this page in your browser and try again.'), ts('Network Error'), 'error');
+      switch (status) {
+        case 'Forbidden':
+          title = ts('Access Denied');
+          msg = ts('Ensure you are still logged in and have permission to access this feature.');
+          break;
+        default:
+          msg = ts('Unable to reach the server. Please refresh this page in your browser and try again.');
+      }
+      CRM.alert(msg, title, 'error');
     },
     _onError: function(data) {
       this.element.attr('data-unsaved-changes', 'false').trigger('crmAjaxError', data);
         that._handleOrderLinks();
         that.element.trigger('crmLoad', data);
         that.options.crmForm && that.element.trigger('crmFormLoad', data);
-      }).fail(function() {
-        that._onFailure();
+      }).fail(function(data, msg, status) {
+        that._onFailure(data, status);
       });
     },
     // Perform any cleanup needed before removing/replacing content