@@ -32,20 +32,28 @@ export class SQLiteCloudWebsocketConnection extends SQLiteCloudConnection {
3232const connectionstring = this . config . connectionstring as string
3333const gatewayUrl = this . config ?. gatewayurl || `${ this . config . host === 'localhost' ?'ws' :'wss' } ://${ this . config . host as string } :4000`
3434this . socket = io ( gatewayUrl , { auth :{ token :connectionstring } } )
35-
35+
3636this . socket . on ( 'connect' , ( ) => {
3737callback ?. call ( this , null )
3838} )
3939
40- this . socket . on ( 'disconnect' , ( reason ) => {
40+ this . socket . on ( 'disconnect' , reason => {
4141this . close ( )
4242callback ?. call ( this , new SQLiteCloudError ( 'Disconnected' , { errorCode :'ERR_CONNECTION_ENDED' , cause :reason } ) )
4343} )
4444
45+ this . socket . on ( 'connect_error' , ( error :any ) => {
46+ this . close ( )
47+ callback ?. call (
48+ this ,
49+ new SQLiteCloudError ( JSON . parse ( error . context . responseText ) . message || 'Connection error' , { errorCode :'ERR_CONNECTION_ERROR' } )
50+ )
51+ } )
52+
4553this . socket . on ( 'error' , ( error :Error ) => {
4654this . close ( )
4755callback ?. call ( this , new SQLiteCloudError ( 'Connection error' , { errorCode :'ERR_CONNECTION_ERROR' , cause :error } ) )
48- } )
56+ } )
4957}
5058} catch ( error ) {
5159callback ?. call ( this , error as Error )