1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-22 11:13:46 +00:00
This commit is contained in:
Kyle Spearrin
2016-09-21 15:21:50 -04:00
parent 6281b1d106
commit 7d2a16c1f4
8 changed files with 30 additions and 19 deletions

View File

@@ -1,4 +1,4 @@
function ApiService(tokenService) {
function ApiService(tokenService) {
this.baseUrl = 'https://api.bitwarden.com';
this.tokenService = tokenService;
@@ -269,6 +269,11 @@ function initApiService() {
// Helpers
function handleError(errorCallback, jqXHR, textStatus, errorThrown) {
if (jqXHR.status === 401 || jqXHR.status === 403) {
chrome.runtime.sendMessage(null, { command: 'logout' });
return;
}
errorCallback(new ErrorResponse(jqXHR));
}
};

View File

@@ -1,4 +1,4 @@
function FolderService(cryptoService, userService, apiService) {
function FolderService(cryptoService, userService, apiService) {
this.cryptoService = cryptoService;
this.userService = userService;
this.apiService = apiService;
@@ -29,7 +29,7 @@ function initFolderService() {
chrome.storage.local.get(foldersKey, function (obj) {
var folders = obj[foldersKey];
if (id in folders) {
if (folders && id in folders) {
callback(new Folder(folders[id]));
return;
}
@@ -97,10 +97,14 @@ function initFolderService() {
request = new FolderRequest(folder);
if (!folder.id) {
self.apiService.postFolder(request, apiSuccess, handleError);
self.apiService.postFolder(request, apiSuccess, function (response) {
handleError(response, deferred)
});
}
else {
self.apiService.putFolder(folder.id, request, apiSuccess, handleError);
self.apiService.putFolder(folder.id, request, apiSuccess, function (response) {
handleError(response, deferred)
});
}
function apiSuccess(response) {
@@ -219,4 +223,8 @@ function initFolderService() {
});
});
};
function handleError(error, deferred) {
deferred.reject(error);
}
};

View File

@@ -1,4 +1,4 @@
function SiteService(cryptoService, userService, apiService) {
function SiteService(cryptoService, userService, apiService) {
this.cryptoService = cryptoService;
this.userService = userService;
this.apiService = apiService;
@@ -43,7 +43,7 @@ function initSiteService() {
chrome.storage.local.get(sitesKey, function (obj) {
var sites = obj[sitesKey];
if (id in sites) {
if (sites && id in sites) {
callback(new Site(sites[id]));
return;
}
@@ -254,10 +254,6 @@ function initSiteService() {
};
function handleError(error, deferred) {
if (error.status === 401 || error.status === 403) {
// TODO: logout
}
deferred.reject(error);
}
};