@@ -32,10 +32,13 @@ type (
3232)
3333
3434// NewDefaultConnectionHandler creates a new connection
35- func NewDefaultConnectionHandler (config * Config ) (* DefaultConnectionHandler , error ) {
35+ func NewDefaultConnectionHandler (config * Config ) (
36+ * DefaultConnectionHandler ,
37+ error ,
38+ ) {
3639 // Check if the config is nil
3740 if config == nil {
38- return nil , NilClientError
41+ return nil , ErrNilClient
3942 }
4043
4144 // Set client options
@@ -54,21 +57,21 @@ func NewDefaultConnectionHandler(config *Config) (*DefaultConnectionHandler, err
5457func (d * DefaultConnectionHandler ) Connect () (* mongo.Client , error ) {
5558 // Check if the connection is already established
5659 if d .Client != nil {
57- return d .Client , godatabases .AlreadyConnectedError
60+ return d .Client , godatabases .ErrAlreadyConnected
5861 }
5962
6063 // Connect to MongoDB
6164 client , err := mongo .Connect (d .Ctx , d .ClientOptions )
6265
6366 // Create MongoDB Connection struct
6467 if err != nil {
65- return nil , godatabases .FailedToConnectError
68+ return nil , godatabases .ErrConnectionFailed
6669 }
6770
6871 // Check the connection
6972 err = client .Ping (context .Background (), nil )
7073 if err != nil {
71- return nil , godatabases .FailedToPingError
74+ return nil , godatabases .ErrPingFailed
7275 }
7376
7477 // Set client
@@ -81,7 +84,7 @@ func (d *DefaultConnectionHandler) Connect() (*mongo.Client, error) {
8184func (d * DefaultConnectionHandler ) GetClient () (* mongo.Client , error ) {
8285 // Check if the connection is established
8386 if d .Client == nil {
84- return nil , godatabases .NotConnectedError
87+ return nil , godatabases .ErrNotConnected
8588 }
8689
8790 return d .Client , nil
@@ -98,7 +101,7 @@ func (d *DefaultConnectionHandler) Disconnect() {
98101 // Close the connection
99102 d .Cancel ()
100103 if err := d .Client .Disconnect (d .Ctx ); err != nil {
101- panic (godatabases .FailedToDisconnectError )
104+ panic (godatabases .ErrFailedToDisconnect )
102105 }
103106 }()
104107}
0 commit comments