Throw IllegalArgumentException when database name not in uri

This commit is contained in:
Chris Broome 2018-12-04 21:20:25 -05:00
parent aa08f4b58c
commit 9d34fc0231
No known key found for this signature in database
GPG key ID: 1069B8DCF35855B0
2 changed files with 3 additions and 3 deletions

View file

@ -236,8 +236,8 @@
(let [uri (MongoClientURI. uri-string) (let [uri (MongoClientURI. uri-string)
conn (MongoClient. uri) conn (MongoClient. uri)
dbName (.getDatabase uri)] dbName (.getDatabase uri)]
(if (nil? dbName) (if (not dbName)
(throw (Exception. "No database name specified in uri")) (throw (IllegalArgumentException. "No database name specified in uri"))
(let [db (.getDB conn dbName)] (let [db (.getDB conn dbName)]
{:conn conn :db db})))) {:conn conn :db db}))))

View file

@ -73,4 +73,4 @@
(deftest connect-to-uri-without-db-name (deftest connect-to-uri-without-db-name
(let [uri "mongodb://localhost:27017"] (let [uri "mongodb://localhost:27017"]
(is (thrown? Exception (mg/connect-via-uri uri))))) (is (thrown? IllegalArgumentException (mg/connect-via-uri uri)))))