зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1056918 - Allow distinguishing between 'not found' and 'database error' programmatically r=standard8
This commit is contained in:
Родитель
94631455e0
Коммит
933182ec4c
|
@ -489,6 +489,9 @@ let LoopContactsInternal = Object.freeze({
|
|||
* finished. The first argument passed will be an
|
||||
* `Error` object or `null`. The second argument will
|
||||
* be the contact object, if successful.
|
||||
* If no object matching guid could be found,
|
||||
* then the callback is called with both arguments
|
||||
* set to `null`.
|
||||
*/
|
||||
get: function(guid, callback) {
|
||||
LoopStorage.getStore(kObjectStoreName, (err, store) => {
|
||||
|
@ -507,8 +510,7 @@ let LoopContactsInternal = Object.freeze({
|
|||
|
||||
request.onsuccess = event => {
|
||||
if (!event.target.result) {
|
||||
callback(new Error("Contact with " + kKeyPath + " '" +
|
||||
guid + "' could not be found"));;
|
||||
callback(null, null);
|
||||
return;
|
||||
}
|
||||
let contact = extend({}, event.target.result);
|
||||
|
@ -528,6 +530,9 @@ let LoopContactsInternal = Object.freeze({
|
|||
* finished. The first argument passed will be an
|
||||
* `Error` object or `null`. The second argument will
|
||||
* be the contact object, if successfull.
|
||||
* If no object matching serviceId could be found,
|
||||
* then the callback is called with both arguments
|
||||
* set to `null`.
|
||||
*/
|
||||
getByServiceId: function(serviceId, callback) {
|
||||
LoopStorage.getStore(kObjectStoreName, (err, store) => {
|
||||
|
@ -547,8 +552,7 @@ let LoopContactsInternal = Object.freeze({
|
|||
|
||||
request.onsuccess = event => {
|
||||
if (!event.target.result) {
|
||||
callback(new Error("Contact with " + kServiceIdIndex + " '" +
|
||||
serviceId + "' could not be found"));
|
||||
callback(null, null);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -658,6 +662,11 @@ let LoopContactsInternal = Object.freeze({
|
|||
return;
|
||||
}
|
||||
|
||||
if (!contact) {
|
||||
callback(new Error("Contact with " + kKeyPath + " '" +
|
||||
guid + "' could not be found"));
|
||||
}
|
||||
|
||||
LoopStorage.getStore(kObjectStoreName, (err, store) => {
|
||||
if (err) {
|
||||
callback(err);
|
||||
|
@ -702,6 +711,11 @@ let LoopContactsInternal = Object.freeze({
|
|||
return;
|
||||
}
|
||||
|
||||
if (!contact) {
|
||||
callback(new Error("Contact with " + kKeyPath + " '" +
|
||||
guid + "' could not be found"));
|
||||
}
|
||||
|
||||
contact.blocked = true;
|
||||
this.update(contact, callback);
|
||||
});
|
||||
|
@ -723,6 +737,11 @@ let LoopContactsInternal = Object.freeze({
|
|||
return;
|
||||
}
|
||||
|
||||
if (!contact) {
|
||||
callback(new Error("Contact with " + kKeyPath + " '" +
|
||||
guid + "' could not be found"));
|
||||
}
|
||||
|
||||
contact.blocked = false;
|
||||
this.update(contact, callback);
|
||||
});
|
||||
|
|
|
@ -230,10 +230,9 @@ add_task(function* () {
|
|||
|
||||
// Get a non-existent contact.
|
||||
deferred = Promise.defer();
|
||||
LoopContacts.get(1000, err => {
|
||||
Assert.ok(err, "There should be an error");
|
||||
Assert.equal(err.message, "Contact with _guid '1000' could not be found",
|
||||
"Error message should be correct");
|
||||
LoopContacts.get(1000, (err, contact) => {
|
||||
Assert.ok(!err, "There shouldn't be an error");
|
||||
Assert.ok(!contact, "There shouldn't be a contact");
|
||||
deferred.resolve();
|
||||
});
|
||||
yield deferred.promise;
|
||||
|
@ -250,10 +249,9 @@ add_task(function* () {
|
|||
LoopContacts.remove(toRemove, err => {
|
||||
Assert.ok(!err, "There shouldn't be an error");
|
||||
|
||||
LoopContacts.get(toRemove, err => {
|
||||
Assert.ok(err, "There should be an error");
|
||||
Assert.equal(err.message, "Contact with _guid '" + toRemove + "' could not be found",
|
||||
"Error message should be correct");
|
||||
LoopContacts.get(toRemove, (err, contact) => {
|
||||
Assert.ok(!err, "There shouldn't be an error");
|
||||
Assert.ok(!contact, "There shouldn't be a contact");
|
||||
deferred.resolve();
|
||||
});
|
||||
});
|
||||
|
@ -261,10 +259,9 @@ add_task(function* () {
|
|||
|
||||
// Remove a non-existing contact.
|
||||
deferred = Promise.defer();
|
||||
LoopContacts.remove(1000, err => {
|
||||
Assert.ok(err, "There should be an error");
|
||||
Assert.equal(err.message, "Contact with _guid '1000' could not be found",
|
||||
"Error message should be correct");
|
||||
LoopContacts.remove(1000, (err, contact) => {
|
||||
Assert.ok(!err, "There shouldn't be an error");
|
||||
Assert.ok(!contact, "There shouldn't be a contact");
|
||||
deferred.resolve();
|
||||
});
|
||||
yield deferred.promise;
|
||||
|
@ -323,7 +320,7 @@ add_task(function* () {
|
|||
_guid: 1000,
|
||||
bday: newBday
|
||||
};
|
||||
LoopContacts.update(toUpdate, err => {
|
||||
LoopContacts.update(toUpdate, (err, contact) => {
|
||||
Assert.ok(err, "There should be an error");
|
||||
Assert.equal(err.message, "Contact with _guid '1000' could not be found",
|
||||
"Error message should be correct");
|
||||
|
|
Загрузка…
Ссылка в новой задаче