I am connecting to MongoDB with a Spring application. Basic configurations are in a properties file, I have some Mongo configs there. I have a custom Configuration class for MongoDB options to set the timeout limits.
When I query for multiple entries, I often get Connection Timeout errors as a response.
Question: I would like to be able to handle timeout errors, so I can send a custom message to the client whenever connection reaches timeout. Where/how is it possible?
You can catch
MongoTimeoutException
and perform any action within thecatch
block. PFB an example: