summaryrefslogtreecommitdiff
path: root/share/server
diff options
context:
space:
mode:
authorJohn Christopher Anderson <jchris@apache.org>2009-08-05 18:11:45 +0000
committerJohn Christopher Anderson <jchris@apache.org>2009-08-05 18:11:45 +0000
commit39ace2d0fa0d3700566bbc453b6518b0a6ff83c3 (patch)
tree990f11712b5943b084c6a737a0fa45866c8a97c5 /share/server
parent53ce56f423a64da476e754f5962a89d0c8eb02d6 (diff)
proper handling of 406 Not Acceptable errors in list and show functions
git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@801345 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'share/server')
-rw-r--r--share/server/render.js33
1 files changed, 19 insertions, 14 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) {