Created
October 11, 2017 16:57
-
-
Save victorwpbastos/89567fbfcbd27d37b6f2189754ea25fd to your computer and use it in GitHub Desktop.
Ajax retry
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.ajaxPrefilter((options, originalOptions, jqXHR) => { | |
let dfd = $.Deferred(); | |
if (options.resolved) { | |
this.showLogin = false; | |
return; | |
} | |
jqXHR.done(dfd.resolve); | |
jqXHR.fail(() => { | |
if (jqXHR.status === 401) { | |
let opts = Object.assign({}, originalOptions, { resolved: true }); | |
this.lastRequest = { promise: dfd, options: opts }; | |
this.showLogin = true; | |
} else { | |
dfd.reject(jqXHR); | |
} | |
}); | |
return dfd.promise(jqXHR); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment