Sorry if I missed this in the documentation, but I'm having trouble figuring out how to handle a duplicate key error when returned from a monger insert.
(let [result (monger-collection/insert user-collection-name new-user)]
(if (monger-result/has-error? result)
(cheshire/generate-string {:error "Something went wrong"})
(cheshire/generate-string new-user)))
(catch Throwable t
(error-response t)))))
Initially I thought the has-error? function would do the trick but an exception is thrown instead. In catching that I seem to get the raw response of the mongodb as the Throwable's message, so I started to decode and parse that, but is there some way I could do that with monger's API?
Ultimately I want to just grab the error code and return that to the client.
Justin