Skip to content
This repository has been archived by the owner on Dec 22, 2023. It is now read-only.

Commit

Permalink
Fixed #3 added restheartProvider.onNetworkError(callback)
Browse files Browse the repository at this point in the history
  • Loading branch information
22Viig committed Mar 23, 2016
1 parent 80da042 commit 26a824d
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
4 changes: 4 additions & 0 deletions angular-restheart.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@
this.onUnauthenticated = f;
};

this.onNetworkError = function (f) {
this.onNetworkError = f;
};

this.$get = function () {
return this;
};
Expand Down
21 changes: 20 additions & 1 deletion services/rh.factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
// check if session expired
var te = handleTokenExpiration(response);
var f = handleForbidden(response);
return !(te || f); // if handled --> false
var ne = handleNetworkError(response);
return !(te || f || ne); // if handled --> false
});

RestangularConfigurer.setRequestInterceptor(function (elem, operation) {
Expand Down Expand Up @@ -111,6 +112,24 @@

return false; // not handled
}

function handleNetworkError(response) {
if (response.status === -1) {
localStorageService.set('rh_networkError', {
'why': 'network_error',
"path": $location.path(),
"state": $state.current.name,
"params": $stateParams
});
// call configured call back, if any
if (angular.isFunction(restheart.onNetworkError)) {
restheart.onNetworkError($location, $state);
}
return true; // handled
}

//return true; // not handled
}
});
}
})();
20 changes: 20 additions & 0 deletions services/rhlogic.factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
RestangularConfigurer.setErrorInterceptor(function (response, deferred, responseHandler) {
// check if session expired
var f = handleUnauthenticated(response);
var ne = handleNetworkError(response);
return !(ne || f); // if handled --> false
return f; // if handled --> false
});

Expand All @@ -44,6 +46,24 @@

//return true; // not handled
}

function handleNetworkError(response) {
if (response.status === -1) {
localStorageService.set('rh_networkError', {
'why': 'network_error',
"path": $location.path(),
"state": $state.current.name,
"params": $stateParams
});
// call configured call back, if any
if (angular.isFunction(restheart.onNetworkError)) {
restheart.onNetworkError($location, $state);
}
return true; // handled
}

//return true; // not handled
}
});
}
})();

0 comments on commit 26a824d

Please sign in to comment.