summaryrefslogtreecommitdiff
path: root/assets/js/core
diff options
context:
space:
mode:
authorVadim Zhukov <persgray@gmail.com>2018-10-01 18:59:42 +0300
committerFrédéric Guillot <fred@kanboard.net>2018-10-01 17:46:50 -0700
commit497f36983c7b02ca8579f785da62efba88e22656 (patch)
tree9456f90f9c2ca516391590880541641fa27d77ae /assets/js/core
parent1db83cddd019567cb0e059376fb59b89809025cf (diff)
Do not try to redirect to login page when offline
Diffstat (limited to 'assets/js/core')
-rw-r--r--assets/js/core/http.js33
1 files changed, 29 insertions, 4 deletions
diff --git a/assets/js/core/http.js b/assets/js/core/http.js
index 3e02a4d7..5c669f63 100644
--- a/assets/js/core/http.js
+++ b/assets/js/core/http.js
@@ -1,5 +1,7 @@
KB.http.request = function (method, url, headers, body) {
var successCallback = function() {};
+ var authErrorCallback = function() {};
+ var netErrorCallback = function() {};
var errorCallback = function() {};
function parseResponse(request) {
@@ -42,10 +44,22 @@ KB.http.request = function (method, url, headers, body) {
if (request.readyState === XMLHttpRequest.DONE) {
var response = parseResponse(request);
- if (request.status === 200) {
- successCallback(response);
- } else {
- errorCallback(response);
+ // errorCallback still gets called for compatibility
+ switch (request.status) {
+ case 200:
+ successCallback(response);
+ return;
+ case 401:
+ authErrorCallback(response);
+ errorCallback(response);
+ break;
+ case 0:
+ netErrorCallback(response);
+ errorCallback(response);
+ break;
+ default:
+ errorCallback(response);
+ break;
}
}
};
@@ -59,6 +73,17 @@ KB.http.request = function (method, url, headers, body) {
return this;
};
+ this.authError = function (callback) {
+ authErrorCallback = callback;
+ return this;
+ };
+
+ this.netError = function (callback) {
+ netErrorCallback = callback;
+ return this;
+ };
+
+ // deprecated
this.error = function (callback) {
errorCallback = callback;
return this;