Skip to content

Commit ebbaf74

Browse files
Merge pull request #256 from sqlitecloud/fix-connect-error-message
fix(ws): error message
2 parents 2cfc907 + 72d908e commit ebbaf74

File tree

5 files changed

+58
-20
lines changed

5 files changed

+58
-20
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -309,10 +309,8 @@ jobs:
309309
strategy:
310310
fail-fast: false
311311
matrix:
312-
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
312+
os: [macos-14, macos-15]
313313
include:
314-
- os: macos-13
315-
version: '16.4'
316314
- os: macos-14
317315
version: '17'
318316
- os: macos-15
@@ -437,10 +435,8 @@ jobs:
437435
strategy:
438436
fail-fast: false
439437
matrix:
440-
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
438+
os: [macos-14, macos-15]
441439
include:
442-
- os: macos-13
443-
version: '16.4'
444440
- os: macos-14
445441
version: '17'
446442
- os: macos-15

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@sqlitecloud/drivers",
3-
"version": "1.0.653",
3+
"version": "1.0.715",
44
"description": "SQLiteCloud drivers for Typescript/Javascript in edge, web and node clients",
55
"main": "./lib/index.js",
66
"types": "./lib/index.d.ts",

src/drivers/connection-ws.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,16 @@ export class SQLiteCloudWebsocketConnection extends SQLiteCloudConnection {
4444

4545
this.socket.on('connect_error', (error: any) => {
4646
this.close()
47-
callback?.call(
48-
this,
49-
new SQLiteCloudError(JSON.parse(error.context.responseText).message || 'Connection error', { errorCode: 'ERR_CONNECTION_ERROR' })
50-
)
47+
let message = error.message || 'Connection error'
48+
if (typeof error.context == 'object' && error.context.responseText) {
49+
try {
50+
const parsed = JSON.parse(error.context.responseText)
51+
message = parsed?.message || error.context.responseText
52+
} catch {
53+
message = error.context.responseText
54+
}
55+
}
56+
callback?.call(this, new SQLiteCloudError(message, { errorCode: 'ERR_CONNECTION_ERROR' }))
5157
})
5258

5359
this.socket.on('error', (error: Error) => {

test/connection-ws.test.ts

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,7 @@ import { SQLiteCloudConnection } from '../src/drivers/connection'
66
import { SQLiteCloudWebsocketConnection } from '../src/drivers/connection-ws'
77
import { SQLiteCloudCommand } from '../src/drivers/types'
88
import { SQLiteCloudError } from '../src/index'
9-
import {
10-
EXPECT_SPEED_MS,
11-
getChinookConfig,
12-
getChinookWebsocketConnection,
13-
LONG_TIMEOUT,
14-
WARN_SPEED_MS
15-
} from './shared'
9+
import { EXPECT_SPEED_MS, getChinookConfig, getChinookWebsocketConnection, LONG_TIMEOUT, WARN_SPEED_MS } from './shared'
1610

1711
describe('connection-ws', () => {
1812
let chinook: SQLiteCloudConnection
@@ -78,6 +72,48 @@ describe('connection-ws', () => {
7872
})
7973
})
8074
*/
75+
76+
it(
77+
'should catch connect_error on connection errors',
78+
done => {
79+
const configObj = getChinookConfig()
80+
configObj.usewebsocket = true
81+
configObj.host = 'non.existing.host.name'
82+
let connection: SQLiteCloudWebsocketConnection | null = null
83+
connection = new SQLiteCloudWebsocketConnection(configObj, error => {
84+
try {
85+
expect(error).toBeDefined()
86+
expect(error?.message).toContain('Error: getaddrinfo ENOTFOUND non.existing.host.name')
87+
connection?.close()
88+
} finally {
89+
done()
90+
}
91+
})
92+
},
93+
LONG_TIMEOUT
94+
)
95+
96+
// skip this test since it requires a paused free node
97+
it.skip(
98+
'should catch connect_error when node is scaled down',
99+
done => {
100+
const configObj = getChinookConfig("sqlitecloud://paused-node")
101+
configObj.usewebsocket = true
102+
let connection: SQLiteCloudWebsocketConnection | null = null
103+
connection = new SQLiteCloudWebsocketConnection(configObj, error => {
104+
try {
105+
expect(error).toBeDefined()
106+
const m = error?.message
107+
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)
108+
connection?.close()
109+
} finally {
110+
done()
111+
}
112+
})
113+
},
114+
LONG_TIMEOUT
115+
)
116+
81117
describe('send test commands', () => {
82118
it('should test integer', done => {
83119
chinook.sendCommands('TEST INTEGER', (error, results) => {

0 commit comments

Comments
 (0)