handle http error codes in cloudstorage dao

This commit is contained in:
Tankred Hase 2013-10-17 23:11:36 +02:00
parent 5d5bfe89bb
commit 4bcc1d6bdf
1 changed files with 12 additions and 45 deletions

View File

@ -24,7 +24,8 @@ define(['jquery', 'js/app-config'], function($, app) {
},
error: function(xhr, textStatus, err) {
callback({
errMsg: xhr.status + ': ' + xhr.statusText,
code: xhr.status,
errMsg: xhr.statusText,
err: err
});
}
@ -45,7 +46,8 @@ define(['jquery', 'js/app-config'], function($, app) {
},
error: function(xhr, textStatus, err) {
callback({
errMsg: xhr.status + ': ' + xhr.statusText,
code: xhr.status,
errMsg: xhr.statusText,
err: err
});
}
@ -64,7 +66,8 @@ define(['jquery', 'js/app-config'], function($, app) {
},
error: function(xhr, textStatus, err) {
callback({
errMsg: xhr.status + ': ' + xhr.statusText,
code: xhr.status,
errMsg: xhr.statusText,
err: err
});
}
@ -146,6 +149,12 @@ define(['jquery', 'js/app-config'], function($, app) {
var uri = app.config.cloudUrl + '/publickey/user/' + userId;
self.get(uri, function(err, keys) {
// not found
if (err && err.code === 404) {
callback();
return;
}
if (err) {
callback(err);
return;
@ -184,47 +193,5 @@ define(['jquery', 'js/app-config'], function($, app) {
self.remove(uri, callback);
};
//
// Ecrypted Private Key
//
/**
* Fetch private key by id
*/
self.getPrivateKey = function(keyId, callback) {
var uri = app.config.cloudUrl + '/privatekey/key/' + keyId;
self.get(uri, function(err, key) {
if (err) {
callback(err);
return;
}
if (!key || !key._id) {
callback({
errMsg: 'No private key for that user!'
});
return;
}
callback(null, key);
});
};
/**
* Persist encrypted private key to cloud service
*/
self.putPrivateKey = function(privkey, callback) {
var uri = app.config.cloudUrl + '/privatekey/user/' + privkey.userId + '/key/' + privkey._id;
self.put(privkey, uri, callback);
};
/**
* Delete the private key from the cloud storage service
*/
self.removePrivateKey = function(keyId, callback) {
var uri = app.config.cloudUrl + '/privatekey/key/' + keyId;
self.remove(uri, callback);
};
return self;
});