soitgoes/LoveSeat — Issue #15: CouchClient.HasDatabase Method
Author: firkinfedup
Created: 2011-10-13 15:34:33+00:00
State: open

Hi there,

I had to make a modification to the CouchDatabase.HasDatabase method, as it was it was causing strange timeout issues to occur with subsequent calls. I believe the reason for this is that it was always returning "True" as it was due to CouchDB returning a 200 status code and some error JSON even if it doesn't exist, the method was only checking for a 200 status code.

public bool HasDatabase(string databaseName)
{
var request = GetRequest(baseUri + databaseName);
request.Timeout = -1;

HttpWebResponse response = request.GetResponse();
Document pDocResult = new Document(response.GetResponseString());

if (pDocResult["error"] == null)
{
return (true);
}
else if (pDocResult["error"].Value() == "not_found")
{
return (false);
}
else
throw new Exception(pDocResult["error"].Value());
}