couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ben Ramsey <>
Subject Re: 412 on update
Date Tue, 21 Oct 2008 16:33:04 GMT
On 10/21/08 4:01 AM, Jonathan Moss wrote:
> Hi everyone,
> I am using the CouchDB PHP library (from
> to
> communicate with the database an I am having some issues updating a
> design document. When I try to save the design document I receive a 412
> HTTP status code. The code below is a simplification of what I am doing
> but should explain what I am trying to do.
> $objCouch = new Couch(array("host" => localhost, "port" => 5984));
> $objDesignDoc = $objCouch->database($strDB)->get("_design/ADesignDoc";
> $objFunction = new stdClass();
> $objFunction->map = "function(doc){if(doc.Type = 'ANode'){emit(doc.Name,
> doc);}}";
> $objDesignDoc->views->$strFunc = $objFunction;
> $objDesignDoc->save();
> echo "Status: " . $objDesignDoc->lastStatusCode . "\n";
> What does a 412 status code mean in this context and does anyone have
> any idea what I can do to fix it?

I'm not sure what a 412 means in this context, but I can tell you what a 412 
*should* mean. :-)

412 is the HTTP status code for "Precondition Failed." From Section 10.4.13 of 
RFC 2616:

"The precondition given in one or more of the request-header fields evaluated to 
false when it was tested on the server. This response code allows the client to 
place preconditions on the current resource metainformation (header field data) 
and thus prevent the requested method from being applied to a resource other 
than the one intended."

Thus, the point is that the client (your application connecting to Couch DB) can 
set one or more headers that the server can check. If any of them evaluate to 
false on the server, then the server would send a 412 Precondition Failed 
response to let you know that a precondition you set failed, so it can't return 
a response.

I'm not sure if that's what Couch DB is doing in this case, but I hope this 
helps you narrow down the problem.

Ben Ramsey

View raw message