Commit 9e9d22cb authored by Romain Courteaud's avatar Romain Courteaud

IndexedDB: provide some informations in the error message

parent 3d4ead4c
...@@ -209,14 +209,18 @@ ...@@ -209,14 +209,18 @@
}); });
}; };
function handleGet(request, resolve, reject) { function handleGet(store, id, resolve, reject) {
var request = store.get(id);
request.onerror = reject; request.onerror = reject;
request.onsuccess = function () { request.onsuccess = function () {
if (request.result) { if (request.result) {
resolve(request.result); resolve(request.result);
} else { } else {
// XXX How to get ID reject(new jIO.util.jIOError(
reject(new jIO.util.jIOError("Cannot find document", 404)); "IndexedDB: cannot find object '" + id + "' in the '" +
store.name + "' store",
404
));
} }
}; };
} }
...@@ -227,7 +231,8 @@ ...@@ -227,7 +231,8 @@
return new RSVP.Promise(function (resolve, reject) { return new RSVP.Promise(function (resolve, reject) {
var transaction = openTransaction(db, ["metadata"], "readonly"); var transaction = openTransaction(db, ["metadata"], "readonly");
handleGet( handleGet(
transaction.objectStore("metadata").get(id), transaction.objectStore("metadata"),
id,
resolve, resolve,
reject reject
); );
...@@ -260,7 +265,8 @@ ...@@ -260,7 +265,8 @@
); );
} }
handleGet( handleGet(
transaction.objectStore("metadata").get(id), transaction.objectStore("metadata"),
id,
getAttachments, getAttachments,
reject reject
); );
...@@ -388,7 +394,8 @@ ...@@ -388,7 +394,8 @@
result_list.push(result); result_list.push(result);
} }
i += 1; i += 1;
handleGet(store.get(buildKeyPath([id, name, i])), handleGet(store,
buildKeyPath([id, name, i]),
(i <= end_index) ? getPart(i) : resolver, (i <= end_index) ? getPart(i) : resolver,
reject reject
); );
...@@ -397,8 +404,8 @@ ...@@ -397,8 +404,8 @@
getPart(start_index - 1)(); getPart(start_index - 1)();
} }
// XXX Should raise if key is not good // XXX Should raise if key is not good
handleGet(transaction.objectStore("attachment") handleGet(transaction.objectStore("attachment"),
.get(buildKeyPath([id, name])), buildKeyPath([id, name]),
getBlob, getBlob,
reject reject
); );
......
...@@ -493,7 +493,10 @@ ...@@ -493,7 +493,10 @@
}) })
.fail(function (error) { .fail(function (error) {
ok(error instanceof jIO.util.jIOError); ok(error instanceof jIO.util.jIOError);
equal(error.message, "Cannot find document"); equal(
error.message,
"IndexedDB: cannot find object 'inexistent' in the 'metadata' store"
);
equal(error.status_code, 404); equal(error.status_code, 404);
}) })
.fail(function (error) { .fail(function (error) {
...@@ -679,7 +682,10 @@ ...@@ -679,7 +682,10 @@
}) })
.fail(function (error) { .fail(function (error) {
ok(error instanceof jIO.util.jIOError); ok(error instanceof jIO.util.jIOError);
equal(error.message, "Cannot find document"); equal(
error.message,
"IndexedDB: cannot find object 'inexistent' in the 'metadata' store"
);
equal(error.status_code, 404); equal(error.status_code, 404);
}) })
.fail(function (error) { .fail(function (error) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment