Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -309,10 +309,8 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [macos-13, macos-14, macos-15] # macos-12 for ios 15 it's going to be deprecated, it's also using an old version of xcode that is not compatible with react native
os: [macos-14, macos-15]
include:
- os: macos-13
version: '16.4'
- os: macos-14
version: '17'
- os: macos-15
Expand Down Expand Up @@ -437,10 +435,8 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [macos-13, macos-14, macos-15] # macos-12 for ios 15 it's going to be deprecated, it's also using an old version of xcode that is not compatible with react native
os: [macos-14, macos-15]
include:
- os: macos-13
version: '16.4'
- os: macos-14
version: '17'
- os: macos-15
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sqlitecloud/drivers",
"version": "1.0.653",
"version": "1.0.715",
"description": "SQLiteCloud drivers for Typescript/Javascript in edge, web and node clients",
"main": "./lib/index.js",
"types": "./lib/index.d.ts",
Expand Down
14 changes: 10 additions & 4 deletions src/drivers/connection-ws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,16 @@ export class SQLiteCloudWebsocketConnection extends SQLiteCloudConnection {

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' })
)
let message = error.message || 'Connection error'
if (typeof error.context == 'object' && error.context.responseText) {
try {
const parsed = JSON.parse(error.context.responseText)
message = parsed?.message || error.context.responseText
} catch {
message = error.context.responseText
}
}
callback?.call(this, new SQLiteCloudError(message, { errorCode: 'ERR_CONNECTION_ERROR' }))
})

this.socket.on('error', (error: Error) => {
Expand Down
50 changes: 43 additions & 7 deletions test/connection-ws.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,7 @@ import { SQLiteCloudConnection } from '../src/drivers/connection'
import { SQLiteCloudWebsocketConnection } from '../src/drivers/connection-ws'
import { SQLiteCloudCommand } from '../src/drivers/types'
import { SQLiteCloudError } from '../src/index'
import {
EXPECT_SPEED_MS,
getChinookConfig,
getChinookWebsocketConnection,
LONG_TIMEOUT,
WARN_SPEED_MS
} from './shared'
import { EXPECT_SPEED_MS, getChinookConfig, getChinookWebsocketConnection, LONG_TIMEOUT, WARN_SPEED_MS } from './shared'

describe('connection-ws', () => {
let chinook: SQLiteCloudConnection
Expand Down Expand Up @@ -78,6 +72,48 @@ describe('connection-ws', () => {
})
})
*/

it(
'should catch connect_error on connection errors',
done => {
const configObj = getChinookConfig()
configObj.usewebsocket = true
configObj.host = 'non.existing.host.name'
let connection: SQLiteCloudWebsocketConnection | null = null
connection = new SQLiteCloudWebsocketConnection(configObj, error => {
try {
expect(error).toBeDefined()
expect(error?.message).toContain('Error: getaddrinfo ENOTFOUND non.existing.host.name')
connection?.close()
} finally {
done()
}
})
},
LONG_TIMEOUT
)

// skip this test since it requires a paused free node
it.skip(
'should catch connect_error when node is scaled down',
done => {
const configObj = getChinookConfig("sqlitecloud://paused-node")
configObj.usewebsocket = true
let connection: SQLiteCloudWebsocketConnection | null = null
connection = new SQLiteCloudWebsocketConnection(configObj, error => {
try {
expect(error).toBeDefined()
const m = error?.message
expect(error?.message.startsWith('Your free node has been paused due to inactivity. To resume usage, please restart your node from your dashboard: https://dashboard.sqlitecloud.io')).toBe(true)
connection?.close()
} finally {
done()
}
})
},
LONG_TIMEOUT
)

describe('send test commands', () => {
it('should test integer', done => {
chinook.sendCommands('TEST INTEGER', (error, results) => {
Expand Down
Loading