summaryrefslogtreecommitdiff
path: root/share
diff options
context:
space:
mode:
authorJan Lehnardt <jan@apache.org>2010-02-04 23:09:06 +0000
committerJan Lehnardt <jan@apache.org>2010-02-04 23:09:06 +0000
commitff1618779bc85d8f16d6aeebec461fad51b008c5 (patch)
tree253733cda59e10beb486b4903d43f21f795d227c /share
parenta75bc7b281952eed8dda9e0c09e3fe386bbe9f32 (diff)
re-enable 404 handling in show functions while retaining user-friendly error behaviour
git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@906721 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'share')
-rw-r--r--share/server/render.js6
-rw-r--r--share/www/script/test/show_documents.js20
2 files changed, 21 insertions, 5 deletions
diff --git a/share/server/render.js b/share/server/render.js
index 45782d76..11c76373 100644
--- a/share/server/render.js
+++ b/share/server/render.js
@@ -227,7 +227,11 @@ var Render = (function() {
throw(["error", "render_error", "undefined response from show function"]);
}
} catch(e) {
- renderError(e, fun.toSource());
+ if(args[0] === null) {
+ throw(["error", "not_found", "document not found"]);
+ } else {
+ renderError(e, fun.toSource());
+ }
}
};
diff --git a/share/www/script/test/show_documents.js b/share/www/script/test/show_documents.js
index bdb1b73e..2e895838 100644
--- a/share/www/script/test/show_documents.js
+++ b/share/www/script/test/show_documents.js
@@ -22,10 +22,15 @@ couchTests.show_documents = function(debug) {
shows: {
"hello" : stringFun(function(doc, req) {
log("hello fun");
+ log(req);
if (doc) {
return "Hello World";
} else {
- return "Empty World";
+ if(req.id) {
+ return "New World";
+ } else {
+ return "Empty World";
+ }
}
}),
"just-name" : stringFun(function(doc, req) {
@@ -56,6 +61,9 @@ couchTests.show_documents = function(debug) {
"empty" : stringFun(function(doc, req) {
return "";
}),
+ "fail" : stringFun(function(doc, req) {
+ return doc._id;
+ }),
"xml-type" : stringFun(function(doc, req) {
return {
"headers" : {
@@ -161,7 +169,7 @@ couchTests.show_documents = function(debug) {
T(xhr.responseText == "");
// // hello template world (non-existing docid)
- xhr = CouchDB.request("GET", "/test_suite_db/_design/template/_show/hello/nonExistingDoc");
+ xhr = CouchDB.request("GET", "/test_suite_db/_design/template/_show/fail/nonExistingDoc");
T(xhr.status == 404);
var resp = JSON.parse(xhr.responseText);
T(resp.error == "not_found");
@@ -173,8 +181,7 @@ couchTests.show_documents = function(debug) {
// show with missing doc
xhr = CouchDB.request("GET", "/test_suite_db/_design/template/_show/just-name/missingdoc");
T(xhr.status == 404);
- var resp = JSON.parse(xhr.responseText);
- T(resp.error == "not_found");
+ TEquals("No such doc", xhr.responseText);
// show with missing func
xhr = CouchDB.request("GET", "/test_suite_db/_design/template/_show/missing/"+docid);
@@ -350,5 +357,10 @@ couchTests.show_documents = function(debug) {
db.save(doc3);
xhr = CouchDB.request("GET", "/test_suite_db/_design/template/_show/withSlash/a/b/c");
T(xhr.status == 200);
+
+ // hello template world (non-existing docid)
+ xhr = CouchDB.request("GET", "/test_suite_db/_design/template/_show/hello/nonExistingDoc");
+ T(xhr.responseText == "New World");
+
};