MDL-59312 js: Add exception on AJAX error
authorAndrew Nicols <andrew@nicols.co.uk>
Wed, 21 Jun 2017 08:19:29 +0000 (16:19 +0800)
committerJohn Okely <john@moodle.com>
Fri, 23 Jun 2017 02:42:22 +0000 (10:42 +0800)
lib/amd/build/ajax.min.js
lib/amd/src/ajax.js

index 96fcee8..8247f32 100644 (file)
Binary files a/lib/amd/build/ajax.min.js and b/lib/amd/build/ajax.min.js differ
index b0267a8..481247c 100644 (file)
@@ -46,6 +46,18 @@ define(['jquery', 'core/config', 'core/log'], function($, config, Log) {
         var request;
         var response;
 
+        if (responses.error) {
+            // There was an error with the request as a whole.
+            // We need to reject each promise.
+            // Unfortunately this may lead to duplicate dialogues, but each Promise must be rejected.
+            for (; i < requests.length; i++) {
+                request = requests[i];
+                request.deferred.reject(responses);
+            }
+
+            return;
+        }
+
         for (i = 0; i < requests.length; i++) {
             request = requests[i];
 
@@ -81,8 +93,9 @@ define(['jquery', 'core/config', 'core/log'], function($, config, Log) {
      * @private
      * @param {jqXHR} jqXHR The ajax object.
      * @param {string} textStatus The status string.
+     * @param {Error|Object} exception The error thrown.
      */
-    var requestFail = function(jqXHR, textStatus) {
+    var requestFail = function(jqXHR, textStatus, exception) {
         // Reject all the promises.
         var requests = this;
 
@@ -92,9 +105,10 @@ define(['jquery', 'core/config', 'core/log'], function($, config, Log) {
 
             if (unloading) {
                 // No need to trigger an error because we are already navigating.
-                Log.error("Page unload: " + textStatus);
+                Log.error("Page unloaded.");
+                Log.error(exception);
             } else {
-                request.deferred.reject(textStatus);
+                request.deferred.reject(exception);
             }
         }
     };