Skip to content
This repository was archived by the owner on Aug 29, 2023. It is now read-only.

Commit 44d0ba3

Browse files
committed
Provide more details on the console
1 parent 8501745 commit 44d0ba3

File tree

2 files changed

+30
-8
lines changed

2 files changed

+30
-8
lines changed

CHANGES.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
### Changes 3.1.1 (in dev)
22

3-
3+
* Outputting more information to investigate into
4+
unintentionally closed WebSocket connections:
5+
- Allow toasts to stay longer for such errors (2 minutes).
6+
- Provide more details on the console.
7+
48
### Changes 3.1.0
59

610
* Adapted to Cate Web API 3.1.x which changed in an

src/renderer/actions.ts

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@ export function connectWebAPIService(webAPIServiceURL: string): ThunkAction {
337337
};
338338

339339
let keepAliveTimer = null;
340+
const keepAliveSeconds = 5;
340341

341342
webAPIClient.onOpen = () => {
342343
dispatch(setWebAPIClient(webAPIClient));
@@ -345,10 +346,10 @@ export function connectWebAPIService(webAPIServiceURL: string): ThunkAction {
345346
dispatch(loadPreferences());
346347
dispatch(loadDataStores());
347348
dispatch(loadOperations());
348-
keepAliveTimer = setInterval(keepAlive, 2500);
349+
keepAliveTimer = setInterval(keepAlive, keepAliveSeconds * 1000);
349350
};
350351

351-
webAPIClient.onClose = (event) => {
352+
webAPIClient.onClose = (event: CloseEvent) => {
352353
if (keepAliveTimer !== null) {
353354
clearInterval(keepAliveTimer);
354355
}
@@ -359,19 +360,36 @@ export function connectWebAPIService(webAPIServiceURL: string): ThunkAction {
359360
}
360361
// When we end up here, the connection closed unintentionally.
361362
console.error('webAPIClient.onClose:', event);
363+
const closeDetails = `reason=${event.reason}, code=${event.code}, clean=${event.wasClean}`;
364+
showToast(
365+
{
366+
type: 'notification',
367+
text: formatMessage(`Connection to Cate service closed: ${closeDetails}`, event)
368+
},
369+
120 * 1000
370+
);
362371
dispatch(setWebAPIStatus('closed'));
363-
showToast({type: 'notification', text: formatMessage('Connection to Cate service closed', event)});
364372
};
365373

366-
webAPIClient.onError = (event) => {
374+
webAPIClient.onError = (event: ErrorEvent) => {
367375
console.error('webAPIClient.onError:', event);
368376
dispatch(setWebAPIStatus('error'));
369-
showToast({type: 'error', text: formatMessage('Error connecting to Cate service', event)});
377+
showToast(
378+
{
379+
type: 'error',
380+
text: formatMessage('Error connecting to Cate service', event)
381+
}
382+
);
370383
};
371384

372-
webAPIClient.onWarning = (event) => {
385+
webAPIClient.onWarning = (event: Event) => {
373386
console.warn('webAPIClient.onWarning:', event);
374-
showToast({type: 'warning', text: formatMessage('Warning from Cate service', event)});
387+
showToast(
388+
{
389+
type: 'warning',
390+
text: formatMessage('Warning from Cate service', event)
391+
}
392+
);
375393
};
376394
};
377395
}

0 commit comments

Comments
 (0)