Author: jan
Date: Sat Nov 20 12:41:26 2010
New Revision: 1037196

URL: http://svn.apache.org/viewvc?rev=1037196&view=rev
Log:
Send a user friendly error message when rewrite rules are a String,
not a JSON Array.

Modified:
    couchdb/branches/1.0.x/share/www/script/test/rewrite.js
    couchdb/branches/1.0.x/src/couchdb/couch_httpd_rewrite.erl

Modified: couchdb/branches/1.0.x/share/www/script/test/rewrite.js
URL: 
http://svn.apache.org/viewvc/couchdb/branches/1.0.x/share/www/script/test/rewrite.js?rev=1037196&r1=1037195&r2=1037196&view=diff
==============================================================================
--- couchdb/branches/1.0.x/share/www/script/test/rewrite.js (original)
+++ couchdb/branches/1.0.x/share/www/script/test/rewrite.js Sat Nov 20 12:41:26 
2010
@@ -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");
+
+}

Modified: couchdb/branches/1.0.x/src/couchdb/couch_httpd_rewrite.erl
URL: 
http://svn.apache.org/viewvc/couchdb/branches/1.0.x/src/couchdb/couch_httpd_rewrite.erl?rev=1037196&r1=1037195&r2=1037196&view=diff
==============================================================================
--- couchdb/branches/1.0.x/src/couchdb/couch_httpd_rewrite.erl (original)
+++ couchdb/branches/1.0.x/src/couchdb/couch_httpd_rewrite.erl Sat Nov 20 
12:41:26 2010
@@ -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],


Reply via email to