You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@couchdb.apache.org by "Mike Wallace (JIRA)" <ji...@apache.org> on 2015/08/12 19:09:46 UTC

[jira] [Created] (COUCHDB-2772) Return HTTP 400 rather than HTTP 500 on view compilation error

Mike Wallace created COUCHDB-2772:
-------------------------------------

             Summary: Return HTTP 400 rather than HTTP 500 on view compilation error
                 Key: COUCHDB-2772
                 URL: https://issues.apache.org/jira/browse/COUCHDB-2772
             Project: CouchDB
          Issue Type: Bug
      Security Level: public (Regular issues)
          Components: Database Core
            Reporter: Mike Wallace


Attempting to upload a view that doesn't compile will result in an HTTP 500 internal server error response:

$ curl -X PUT http://localhost:5984/ohai
{"ok":true}
$ curl -X PUT http://localhost:5984/ohai/_design/foo -d '{"views":{"doge":{"map":"function(doc) { emit(doc.id, 1); };", "reduce": "wat"}}}'
* Connected to localhost (127.0.0.1) port 5984 (#0)
* Server auth using Basic with user 'admin'
> PUT /ohai/_design/foo HTTP/1.1
> Authorization: Basic YWRtaW46aHNq
> User-Agent: curl/7.37.1
> Host: localhost:5984
> Accept: */*
> Content-Length: 81
> Content-Type: application/x-www-form-urlencoded
> 
* upload completely sent off: 81 out of 81 bytes
< HTTP/1.1 500 Internal Server Error
< X-CouchDB-Body-Time: 0
< X-Couch-Request-ID: e844aa0311
* Server CouchDB/0bf8917 (Erlang OTP/17) is not blacklisted
< Server: CouchDB/0bf8917 (Erlang OTP/17)
< Date: Wed, 12 Aug 2015 14:26:57 GMT
< Content-Type: text/plain; charset=utf-8
< Content-Length: 149
< Cache-Control: must-revalidate
< 
{"error":"compilation_error","reason":"Compilation of the reduce function in the 'doge' view failed: Expression does not eval to a function. (wat)"}

Because the request is supplying an invalid view an HTTP 400 bad request response would be appropriate here, and would make things clearer to the client that the fault lies within the request rather than the server.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)