mirror of
https://github.com/crawlab-team/crawlab.git
synced 2026-01-25 17:42:25 +01:00
fix: enhance MongoDB client connection error handling
- Added a ping check after establishing a MongoDB client connection to ensure the connection is valid. - Implemented error logging for ping failures to improve debugging and provide clearer feedback on connection issues. - Ensured alignment with existing error handling practices in the codebase for consistency and maintainability.
This commit is contained in:
@@ -136,6 +136,11 @@ func newMongoClient(_opts *ClientOptions) (c *mongo.Client, err error) {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = c.Ping(ctx, nil)
|
||||
if err != nil {
|
||||
logger.Errorf("ping mongo error: %v", err)
|
||||
return err
|
||||
}
|
||||
logger.Infof("connected to mongo")
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user