summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--share/www/script/test/view_errors.js9
-rw-r--r--src/mochiweb/mochijson2.erl5
2 files changed, 13 insertions, 1 deletions
diff --git a/share/www/script/test/view_errors.js b/share/www/script/test/view_errors.js
index a8a9be7d..66fdfa69 100644
--- a/share/www/script/test/view_errors.js
+++ b/share/www/script/test/view_errors.js
@@ -40,4 +40,13 @@ couchTests.view_errors = function(debug) {
emit([doc._id, doc.undef], null);
});
T(results.total_rows == 0);
+
+ // querying a view with invalid params should give a resonable error message
+ var xhr = CouchDB.request("POST", "/test_suite_db/_temp_view?startkey=foo", {
+ headers: {"Content-Type": "application/json"},
+ body: JSON.stringify({language: "javascript",
+ map : "function(doc){emit(doc.integer)}"
+ })
+ });
+ T(JSON.parse(xhr.responseText).error == "invalid_json");
};
diff --git a/src/mochiweb/mochijson2.erl b/src/mochiweb/mochijson2.erl
index 668486fc..9b59c7df 100644
--- a/src/mochiweb/mochijson2.erl
+++ b/src/mochiweb/mochijson2.erl
@@ -70,7 +70,10 @@ decoder(Options) ->
%% @spec decode(iolist()) -> json_term()
%% @doc Decode the given iolist to Erlang terms.
decode(S) ->
- json_decode(S, #decoder{}).
+ try json_decode(S, #decoder{})
+ catch
+ _:_ -> throw({invalid_json, S})
+ end.
test() ->
test_all().