diff --git a/package.json b/package.json index ca24cc2..9132740 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@sqlitecloud/drivers", - "version": "1.0.626", + "version": "1.0.653", "description": "SQLiteCloud drivers for Typescript/Javascript in edge, web and node clients", "main": "./lib/index.js", "types": "./lib/index.d.ts", diff --git a/src/drivers/connection-ws.ts b/src/drivers/connection-ws.ts index 1c9e716..094d46f 100644 --- a/src/drivers/connection-ws.ts +++ b/src/drivers/connection-ws.ts @@ -32,20 +32,28 @@ export class SQLiteCloudWebsocketConnection extends SQLiteCloudConnection { const connectionstring = this.config.connectionstring as string const gatewayUrl = this.config?.gatewayurl || `${this.config.host === 'localhost' ? 'ws' : 'wss'}://${this.config.host as string}:4000` this.socket = io(gatewayUrl, { auth: { token: connectionstring } }) - + this.socket.on('connect', () => { callback?.call(this, null) }) - this.socket.on('disconnect', (reason) => { + this.socket.on('disconnect', reason => { this.close() callback?.call(this, new SQLiteCloudError('Disconnected', { errorCode: 'ERR_CONNECTION_ENDED', cause: reason })) }) + this.socket.on('connect_error', (error: any) => { + this.close() + callback?.call( + this, + new SQLiteCloudError(JSON.parse(error.context.responseText).message || 'Connection error', { errorCode: 'ERR_CONNECTION_ERROR' }) + ) + }) + this.socket.on('error', (error: Error) => { this.close() callback?.call(this, new SQLiteCloudError('Connection error', { errorCode: 'ERR_CONNECTION_ERROR', cause: error })) - }) + }) } } catch (error) { callback?.call(this, error as Error)