summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--share/server/render.js33
-rw-r--r--share/www/script/test/show_documents.js9
-rw-r--r--src/couchdb/couch_httpd.erl2
3 files changed, 25 insertions, 19 deletions
diff --git a/share/server/render.js b/share/server/render.js
index 51472672..1a9fc5a5 100644
--- a/share/server/render.js
+++ b/share/server/render.js
@@ -140,18 +140,21 @@ function runProvides(req) {
responseContentType = mimesByKey[bestKey][0];
}
- for (var i=0; i < mimeFuns.length; i++) {
- if (mimeFuns[i][0] == bestKey) {
- bestFun = mimeFuns[i][1];
- break;
- }
+ if (bestKey) {
+ for (var i=0; i < mimeFuns.length; i++) {
+ if (mimeFuns[i][0] == bestKey) {
+ bestFun = mimeFuns[i][1];
+ break;
+ }
+ };
};
-
+
if (bestFun) {
// log("responding with: "+bestKey);
return bestFun();
} else {
- throw({code:406, body:"Not Acceptable: "+accept||bestKey});
+ var supportedTypes = mimeFuns.map(function(mf) {return mimesByKey[mf[0]].join(', ') || mf[0]});
+ throw({error:"not_acceptable", reason:"Content-Type "+(accept||bestKey)+" not supported, try one of: "+supportedTypes.join(', ')});
}
};
@@ -248,13 +251,15 @@ function renderError(m) {
}
function respondError(e, funSrc, htmlErrors) {
- var logMessage = "function raised error: "+e.toString();
- log(logMessage);
- log("stacktrace: "+e.stack);
- var errorMessage = htmlErrors ? htmlRenderError(e, funSrc) : logMessage;
- respond({
- error:"render_error",
- reason:errorMessage});
+ if (e.error && e.reason) {
+ respond(e);
+ } else {
+ var logMessage = "function raised error: "+e.toString();
+ log(logMessage);
+ log("stacktrace: "+e.stack);
+ var errorMessage = htmlErrors ? htmlRenderError(e, funSrc) : logMessage;
+ renderError(errorMessage);
+ }
}
function escapeHTML(string) {
diff --git a/share/www/script/test/show_documents.js b/share/www/script/test/show_documents.js
index 7181a926..59bcd6d3 100644
--- a/share/www/script/test/show_documents.js
+++ b/share/www/script/test/show_documents.js
@@ -318,13 +318,12 @@ couchTests.show_documents = function(debug) {
// test the provides mime matcher without a match
xhr = CouchDB.request("GET", "/test_suite_db/_design/template/_show/provides/"+docid, {
headers: {
- "Accept": 'text/html,application/atom+xml; q=0.9'
+ "Accept": 'text/monkeys'
}
});
- var ct = xhr.getResponseHeader("Content-Type");
- T(/charset=utf-8/.test(ct))
- T(/text\/html/.test(ct))
- T(xhr.responseText == "Ha ha, you said \"plankton\".");
+ var rs = JSON.parse(xhr.responseText);
+ T(rs.error == "not_acceptable")
+
// should fallback on the first one
xhr = CouchDB.request("GET", "/test_suite_db/_design/template/_show/provides/"+docid, {
diff --git a/src/couchdb/couch_httpd.erl b/src/couchdb/couch_httpd.erl
index 766d18d0..fee5004e 100644
--- a/src/couchdb/couch_httpd.erl
+++ b/src/couchdb/couch_httpd.erl
@@ -452,6 +452,8 @@ error_info(not_found) ->
{404, <<"not_found">>, <<"missing">>};
error_info({not_found, Reason}) ->
{404, <<"not_found">>, Reason};
+error_info({not_acceptable, Reason}) ->
+ {406, <<"not_acceptable">>, Reason};
error_info(conflict) ->
{409, <<"conflict">>, <<"Document update conflict.">>};
error_info({forbidden, Msg}) ->