Created
June 18, 2015 10:52
-
-
Save gladiatorAsh/ac4a365d54bdfb0cc580 to your computer and use it in GitHub Desktop.
Ajax Setup
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
$.ajaxSetup({ | |
cache: false, | |
tryCount: 0, | |
retryLimit: 3, | |
error: function (xhr, textStatus, errorThrown) { | |
$.unblockUI(); | |
Spin.stopSpin(); | |
// lang = "HI"; | |
if (xhr.status == 404) { | |
console.log("Service not found"); | |
toastr.error("Something went wrong!! Please try again later ", "Service Error"); | |
return; | |
} | |
if (xhr.status == 401) { | |
console.log("Unauthorized"); | |
toastr.error("You are not authorized to perform this operation", "Service Error"); | |
return; | |
} | |
if (xhr.status == 400) { | |
console.log("Bad Request"); | |
toastr.error("Error occurred while processing the request. Please try again later ", "Service Error"); | |
return; | |
} | |
if (textStatus == "timeout") { | |
/** | |
* If timeout occurs, retry; default no. of retries are 3 | |
* After 3 retries, exit and show error. | |
*/ | |
this.tryCount++; | |
if (this.tryCount < this.retryLimit) { | |
$.ajax(this); | |
return; | |
} | |
else { | |
console.log('Repeated timeout error'); | |
toastr.error("Request timeout. Please try after some time.", "Service Error"); | |
return; | |
} | |
if (xhr.status == 500) { | |
console.log("Internal server error"); | |
toastr.error("Error occurred while processing the request , Please try again later.", "Service Error"); | |
return; | |
} else { | |
console.log("Please contact the administrator"); | |
toastr.error("Error occurred while processing the request.", "Service Error"); | |
return; | |
} | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ajax Settings + Retry times.