MDL-59312 js: Add exception on AJAX error

This commit is contained in:
Andrew Nicols
2017-06-23 10:50:04 +08:00
committed by John Okely
parent cccb1a6d21
commit 6aebb4375f
2 changed files with 18 additions and 4 deletions
+1 -1
View File
@@ -1 +1 @@
define(["jquery","core/config","core/log"],function(a,b,c){var d=!1,e=function(a){var b,c,d=this,e=null,f=0;for(f=0;f<d.length;f++){if(b=d[f],c=a[f],"undefined"==typeof c){e=new Error("missing response");break}if(c.error!==!1){e=c.exception;break}b.deferred.resolve(c.data)}if(null!==e)for(;f<d.length;f++)b=d[f],b.deferred.reject(e)},f=function(a,b){var e=this,f=0;for(f=0;f<e.length;f++){var g=e[f];d?c.error("Page unload: "+b):g.deferred.reject(b)}};return{call:function(c,g,h){a(window).bind("beforeunload",function(){d=!0});var i,j=[],k=[],l=[],m="";for("undefined"==typeof h&&(h=!0),"undefined"==typeof g&&(g=!0),i=0;i<c.length;i++){var n=c[i];j.push({index:i,methodname:n.methodname,args:n.args}),n.deferred=a.Deferred(),k.push(n.deferred.promise()),"undefined"!=typeof n.done&&n.deferred.done(n.done),"undefined"!=typeof n.fail&&n.deferred.fail(n.fail),n.index=i,l.push(n.methodname)}m=l.length<=5?l.sort().join():l.length+"-method-calls",j=JSON.stringify(j);var o={type:"POST",data:j,context:c,dataType:"json",processData:!1,async:g,contentType:"application/json"},p="service.php";h||(p="service-nologin.php");var q=b.wwwroot+"/lib/ajax/"+p+"?sesskey="+b.sesskey+"&info="+m;return g?a.ajax(q,o).done(e).fail(f):(o.success=e,o.error=f,a.ajax(q,o)),k}}});
define(["jquery","core/config","core/log"],function(a,b,c){var d=!1,e=function(a){var b,c,d=this,e=null,f=0;if(a.error)for(;f<d.length;f++)b=d[f],b.deferred.reject(a);else{for(f=0;f<d.length;f++){if(b=d[f],c=a[f],"undefined"==typeof c){e=new Error("missing response");break}if(c.error!==!1){e=c.exception;break}b.deferred.resolve(c.data)}if(null!==e)for(;f<d.length;f++)b=d[f],b.deferred.reject(e)}},f=function(a,b,e){var f=this,g=0;for(g=0;g<f.length;g++){var h=f[g];d?(c.error("Page unloaded."),c.error(e)):h.deferred.reject(e)}};return{call:function(c,g,h){a(window).bind("beforeunload",function(){d=!0});var i,j=[],k=[],l=[],m="";for("undefined"==typeof h&&(h=!0),"undefined"==typeof g&&(g=!0),i=0;i<c.length;i++){var n=c[i];j.push({index:i,methodname:n.methodname,args:n.args}),n.deferred=a.Deferred(),k.push(n.deferred.promise()),"undefined"!=typeof n.done&&n.deferred.done(n.done),"undefined"!=typeof n.fail&&n.deferred.fail(n.fail),n.index=i,l.push(n.methodname)}m=l.length<=5?l.sort().join():l.length+"-method-calls",j=JSON.stringify(j);var o={type:"POST",data:j,context:c,dataType:"json",processData:!1,async:g,contentType:"application/json"},p="service.php";h||(p="service-nologin.php");var q=b.wwwroot+"/lib/ajax/"+p+"?sesskey="+b.sesskey+"&info="+m;return g?a.ajax(q,o).done(e).fail(f):(o.success=e,o.error=f,a.ajax(q,o)),k}}});
+17 -3
View 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);
}
}
};