Skip to content

Commit 2fa8dc1

Browse files
authored
refactor(Client): stricter checks on connect & end
1 parent f7dffca commit 2fa8dc1

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export class Client extends EventEmitter {
7979
* @see end
8080
*/
8181

82-
public connected: boolean;
82+
readonly connected: boolean;
8383

8484
constructor(dbUrl: string, options?: ClientOptions) {
8585
super();
@@ -97,6 +97,8 @@ export class Client extends EventEmitter {
9797
*/
9898

9999
public async connect(): Promise<Client> {
100+
if (this.connected) throw new Error("Client has already been connected.");
101+
100102
await this.client.connect();
101103
this.connected = true;
102104

@@ -117,6 +119,8 @@ export class Client extends EventEmitter {
117119
*/
118120

119121
public async end(): Promise<Client> {
122+
if (!this.connected) throw new Error("Client has not been connected yet.");
123+
120124
await this.client.end();
121125
this.connected = false;
122126

0 commit comments

Comments
 (0)