diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 84ed4c8..3b3fc82 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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 @@ -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 diff --git a/package-lock.json b/package-lock.json index 70ecbbd..64b2125 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@sqlitecloud/drivers", - "version": "1.0.626", + "version": "1.0.715", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@sqlitecloud/drivers", - "version": "1.0.626", + "version": "1.0.715", "license": "MIT", "dependencies": { "buffer": "^6.0.3", diff --git a/package.json b/package.json index 9132740..a5eae21 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/drivers/connection-ws.ts b/src/drivers/connection-ws.ts index 094d46f..0f5352d 100644 --- a/src/drivers/connection-ws.ts +++ b/src/drivers/connection-ws.ts @@ -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) => { diff --git a/test/connection-ws.test.ts b/test/connection-ws.test.ts index 3cf2fd5..72f058a 100644 --- a/test/connection-ws.test.ts +++ b/test/connection-ws.test.ts @@ -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 @@ -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) => {