Commit 8ad93226 authored by Romain Courteaud's avatar Romain Courteaud

ERP5 storage: handle 404 status code

parent 299a0345
...@@ -38,6 +38,8 @@ ...@@ -38,6 +38,8 @@
return getSiteDocument(storage) return getSiteDocument(storage)
.push(function (site_hal) { .push(function (site_hal) {
// XXX need to get modified metadata // XXX need to get modified metadata
return new RSVP.Queue()
.push(function () {
return jIO.util.ajax({ return jIO.util.ajax({
"type": "GET", "type": "GET",
"url": UriTemplate.parse(site_hal._links.traverse.href) "url": UriTemplate.parse(site_hal._links.traverse.href)
...@@ -49,6 +51,14 @@ ...@@ -49,6 +51,14 @@
withCredentials: true withCredentials: true
} }
}); });
})
.push(undefined, function (error) {
if ((error.target !== undefined) &&
(error.target.status === 404)) {
throw new jIO.util.jIOError("Cannot find document: " + id, 404);
}
throw error;
});
}); });
} }
......
...@@ -64,6 +64,35 @@ ...@@ -64,6 +64,35 @@
} }
}); });
test("get inexistent document", function () {
var id = "person_module/20150119_azerty",
traverse_url = domain + "?mode=traverse&relative_url=" +
encodeURIComponent(id);
this.server.respondWith("GET", domain, [200, {
"Content-Type": "application/hal+json"
}, root_hateoas]);
this.server.respondWith("GET", traverse_url, [404, {
"Content-Type": "text/html"
}, ""]);
stop();
expect(3);
this.jio.get(id)
.fail(function (error) {
ok(error instanceof jIO.util.jIOError);
equal(error.message, "Cannot find document: " + id);
equal(error.status_code, 404);
})
.fail(function (error) {
ok(false, error);
})
.always(function () {
start();
});
});
test("get ERP5 document", function () { test("get ERP5 document", function () {
var id = "person_module/20150119_azerty", var id = "person_module/20150119_azerty",
traverse_url = domain + "?mode=traverse&relative_url=" + traverse_url = domain + "?mode=traverse&relative_url=" +
...@@ -136,6 +165,35 @@ ...@@ -136,6 +165,35 @@
} }
}); });
test("allAttachments on inexistent document", function () {
var id = "person_module/20150119_azerty",
traverse_url = domain + "?mode=traverse&relative_url=" +
encodeURIComponent(id);
this.server.respondWith("GET", domain, [200, {
"Content-Type": "application/hal+json"
}, root_hateoas]);
this.server.respondWith("GET", traverse_url, [404, {
"Content-Type": "text/html"
}, ""]);
stop();
expect(3);
this.jio.allAttachments(id)
.fail(function (error) {
ok(error instanceof jIO.util.jIOError);
equal(error.message, "Cannot find document: " + id);
equal(error.status_code, 404);
})
.fail(function (error) {
ok(false, error);
})
.always(function () {
start();
});
});
test("allAttachments ERP5 document", function () { test("allAttachments ERP5 document", function () {
var id = "person_module/20150119_azerty", var id = "person_module/20150119_azerty",
traverse_url = domain + "?mode=traverse&relative_url=" + traverse_url = domain + "?mode=traverse&relative_url=" +
...@@ -322,6 +380,35 @@ ...@@ -322,6 +380,35 @@
}); });
}); });
test("getAttachment: view on inexistent document", function () {
var id = "person_module/1",
traverse_url = domain + "?mode=traverse&relative_url=" +
encodeURIComponent(id) + "&view=foo_view";
this.server.respondWith("GET", domain, [200, {
"Content-Type": "application/hal+json"
}, root_hateoas]);
this.server.respondWith("GET", traverse_url, [404, {
"Content-Type": "text/html"
}, ""]);
stop();
expect(3);
this.jio.getAttachment(id, "view")
.fail(function (error) {
ok(error instanceof jIO.util.jIOError);
equal(error.message, "Cannot find document: " + id);
equal(error.status_code, 404);
})
.fail(function (error) {
ok(false, error);
})
.always(function () {
start();
});
});
test("getAttachment: view uses default form", function () { test("getAttachment: view uses default form", function () {
var id = "person_module/1", var id = "person_module/1",
traverse_url = domain + "?mode=traverse&relative_url=" + traverse_url = domain + "?mode=traverse&relative_url=" +
...@@ -379,6 +466,35 @@ ...@@ -379,6 +466,35 @@
}); });
}); });
test("getAttachment: links on inexistent document", function () {
var id = "person_module/1",
traverse_url = domain + "?mode=traverse&relative_url=" +
encodeURIComponent(id);
this.server.respondWith("GET", domain, [200, {
"Content-Type": "application/hal+json"
}, root_hateoas]);
this.server.respondWith("GET", traverse_url, [404, {
"Content-Type": "text/html"
}, ""]);
stop();
expect(3);
this.jio.getAttachment(id, "links")
.fail(function (error) {
ok(error instanceof jIO.util.jIOError);
equal(error.message, "Cannot find document: " + id);
equal(error.status_code, 404);
})
.fail(function (error) {
ok(false, error);
})
.always(function () {
start();
});
});
test("getAttachment: links uses no form", function () { test("getAttachment: links uses no form", function () {
var id = "person_module/1", var id = "person_module/1",
traverse_url = domain + "?mode=traverse&relative_url=" + traverse_url = domain + "?mode=traverse&relative_url=" +
......
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