@@ -29,10 +29,10 @@ describe('websocket transport helpers', () => {
2929
3030 const connection = Object . create ( SQLiteCloudWebsocketConnection . prototype ) as any
3131 const connectionstring = 'sqlitecloud://host.sqlite.cloud/database?apikey=secret'
32- connection . connectTransport ( { connectionstring, host : 'host.sqlite.cloud' , websocketMaxAttachments : 321 } , jest . fn ( ) )
32+ connection . connectTransport ( { connectionstring, host : 'host.sqlite.cloud' , apikey : 'secret' , websocketMaxAttachments : 321 } , jest . fn ( ) )
3333
34- expect ( mockedIo ) . toHaveBeenCalledWith ( 'wss://host.sqlite.cloud:443' , {
35- auth : { token : connectionstring } ,
34+ expect ( mockedIo ) . toHaveBeenCalledWith ( 'wss://host.gateway. sqlite.cloud:443' , {
35+ auth : { token : 'secret' } ,
3636 parser : expect . objectContaining ( {
3737 Encoder : expect . any ( Function ) ,
3838 Decoder : expect . any ( Function )
@@ -84,6 +84,7 @@ describe('websocket transport helpers', () => {
8484 {
8585 sql : 'SELECT ?' ,
8686 bind : [ '123n' ] ,
87+ database : undefined ,
8788 row : 'array' ,
8889 safe_integer_mode : 'bigint' ,
8990 capabilities : {
@@ -162,6 +163,38 @@ describe('websocket transport helpers', () => {
162163 } )
163164 } )
164165
166+ it ( 'should read gateway errors from the errors array response field' , done => {
167+ const connection = Object . create ( SQLiteCloudWebsocketConnection . prototype ) as any
168+ const emit = jest . fn ( ( _event : string , _payload : any , callback : ( response : any ) => void ) => {
169+ callback ( {
170+ errors : [
171+ {
172+ detail : 'Gateway validation failed.' ,
173+ errorCode : '40001' ,
174+ externalErrorCode : '0' ,
175+ offsetCode : - 1
176+ }
177+ ]
178+ } )
179+ } )
180+ connection . socket = { connected : true , emit }
181+ connection . config = { }
182+
183+ connection . transportCommands ( 'SELECT 1' , ( error : any , results ?: SQLiteCloudRowset ) => {
184+ try {
185+ expect ( results ) . toBeUndefined ( )
186+ expect ( error ) . toBeDefined ( )
187+ expect ( error . message ) . toBe ( 'Gateway validation failed.' )
188+ expect ( error . errorCode ) . toBe ( '40001' )
189+ expect ( error . externalErrorCode ) . toBe ( '0' )
190+ expect ( error . offsetCode ) . toBe ( - 1 )
191+ done ( )
192+ } catch ( error ) {
193+ done ( error as Error )
194+ }
195+ } )
196+ } )
197+
165198 it ( 'should surface an actionable error when socket.io attachment limits are exceeded' , ( ) => {
166199 const handlers : Record < string , ( ...args : any [ ] ) => void > = { }
167200 const socket = {
0 commit comments