Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Commit 3544444

Browse files
committed
Replaced Cloudant exception code 409 with 412 when database already exists
1 parent 0d086a2 commit 3544444

File tree

4 files changed

+6
-4
lines changed

4 files changed

+6
-4
lines changed

CHANGES.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
2.5.0 (Unreleased)
22
==================
33
- [FIXED] Fixed ``TypeError`` when setting revision limits on Python>=3.6.
4+
- [FIXED] Fixed Cloudant exception code 409 with 412 when creating a database that already exists.
45

56
2.4.0 (2017-02-14)
67
==================

src/cloudant/_messages.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,16 @@
7373
101: 'Value must be set to a Database object. Found type: {0}',
7474
102: 'You must provide a url or an account.',
7575
404: 'Database {0} does not exist. Verify that the client is valid and try again.',
76-
409: 'Database {0} already exists.'
76+
412: 'Database {0} already exists.'
7777
}
7878

7979
DATABASE = {
8080
100: 'A general Cloudant database exception was raised.',
8181
101: 'Unexpected index type. Found: {0}',
8282
400: 'Invalid database name during creation. Found: {0}',
8383
401: 'Unauthorized to create database {0}',
84-
409: 'Document with id {0} already exists.'
84+
409: 'Document with id {0} already exists.',
85+
412: 'Database {0} already exists.'
8586
}
8687

8788
DESIGN_DOCUMENT = {

src/cloudant/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ def create_database(self, dbname, **kwargs):
226226
new_db = self._DATABASE_CLASS(self, dbname)
227227
if new_db.exists():
228228
if kwargs.get('throw_on_exists', True):
229-
raise CloudantClientException(409, dbname)
229+
raise CloudantClientException(412, dbname)
230230
new_db.create()
231231
super(CouchDB, self).__setitem__(dbname, new_db)
232232
return new_db

tests/unit/client_tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ def test_create_existing_database(self):
277277
self.client.create_database(dbname)
278278
with self.assertRaises(CloudantClientException) as cm:
279279
self.client.create_database(dbname, throw_on_exists=True)
280-
self.assertEqual(cm.exception.status_code, 409)
280+
self.assertEqual(cm.exception.status_code, 412)
281281

282282
self.client.delete_database(dbname)
283283
self.client.disconnect()

0 commit comments

Comments
 (0)