Skip to content

Commit 80a40f3

Browse files
committed
Preserve error details.
1 parent af20fa2 commit 80a40f3

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

packages/common/src/client/sync/stream/AbstractRemote.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -314,14 +314,15 @@ export abstract class AbstractRemote {
314314

315315
let socketCreationError: Error | undefined;
316316

317+
const url = this.options.socketUrlTransformer(request.url);
317318
const connector = new RSocketConnector({
318319
transport: new WebsocketClientTransport({
319-
url: this.options.socketUrlTransformer(request.url),
320+
url,
320321
wsCreator: (url) => {
321322
const s = this.createSocket(url);
322-
s.addEventListener('error', (e: Event) => {
323-
socketCreationError = new Error('Failed to create connection to websocket: ', (e.target as any).url ?? '');
324-
this.logger.warn('Socket error', e);
323+
s.addEventListener('error', (e: ErrorEvent) => {
324+
socketCreationError = e.error ?? new Error(`Failed to create connection to websocket: ${url}`);
325+
this.logger.warn('Socket error', socketCreationError);
325326
});
326327
return s;
327328
}
@@ -351,7 +352,7 @@ export abstract class AbstractRemote {
351352
* On React native the connection exception can be `undefined` this causes issues
352353
* with detecting the exception inside async-mutex
353354
*/
354-
throw new Error(`Could not connect to PowerSync instance: ${JSON.stringify(ex ?? socketCreationError)}`);
355+
throw ex ?? socketCreationError;
355356
}
356357

357358
const stream = new DataStream({

0 commit comments

Comments
 (0)