From c39629cfa9151bb1776b296f22adf87bcd00b6af Mon Sep 17 00:00:00 2001 From: Jan Lehnardt Date: Sat, 20 Nov 2010 12:41:26 +0000 Subject: Send a user friendly error message when rewrite rules are a String, not a JSON Array. git-svn-id: https://svn.apache.org/repos/asf/couchdb/branches/1.0.x@1037196 13f79535-47bb-0310-9956-ffa450edef68 --- share/www/script/test/rewrite.js | 15 ++++++++++++--- src/couchdb/couch_httpd_rewrite.erl | 5 ++++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/share/www/script/test/rewrite.js b/share/www/script/test/rewrite.js index 66b33d74..ff2d3822 100644 --- a/share/www/script/test/rewrite.js +++ b/share/www/script/test/rewrite.js @@ -365,7 +365,16 @@ couchTests.rewrite = function(debug) { T(result.uuids.length == 1); var first = result.uuids[0]; }); - }); - -} \ No newline at end of file + + // test invalid rewrites + // string + var ddoc = { + _id: "_design/invalid", + rewrites: "[{\"from\":\"foo\",\"to\":\"bar\"}]" + } + db.save(ddoc); + var res = CouchDB.request("GET", "/test_suite_db/_design/invalid/_rewrite/foo"); + TEquals(400, res.status, "should return 400"); + +} diff --git a/src/couchdb/couch_httpd_rewrite.erl b/src/couchdb/couch_httpd_rewrite.erl index ca4ac1f0..6c3d0e3c 100644 --- a/src/couchdb/couch_httpd_rewrite.erl +++ b/src/couchdb/couch_httpd_rewrite.erl @@ -126,7 +126,10 @@ handle_rewrite_req(#httpd{ case couch_util:get_value(<<"rewrites">>, Props) of undefined -> couch_httpd:send_error(Req, 404, <<"rewrite_error">>, - <<"Invalid path.">>); + <<"Invalid path.">>); + Bin when is_binary(Bin) -> + couch_httpd:send_error(Req, 400, <<"rewrite_error">>, + <<"Rewrite rules are a String. They must be a JSON Array.">>); Rules -> % create dispatch list from rules DispatchList = [make_rule(Rule) || {Rule} <- Rules], -- cgit v1.2.3