Skip to content

Commit 6b99dd8

Browse files
committed
tell user about websocket connection failure but dont throw away any data until a reconnect
1 parent 249cecc commit 6b99dd8

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

app/components/InstrumentData.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ export function InstrumentData({ instrumentName }: { instrumentName: string }) {
5959
} = useWebSocket(socketURL, {
6060
shouldReconnect: (closeEvent) => true,
6161
onOpen: () => {
62+
setWebSockErr("");
6263
setLastUpdate(""); // if this is called on a reconnect, we want to clear the last update so we can re-subscribe to everything again
6364
sendJsonMessage(instListSubscription);
6465
},
@@ -168,6 +169,11 @@ export function InstrumentData({ instrumentName }: { instrumentName: string }) {
168169
}
169170
}
170171
},
172+
onError: (err) => {
173+
setWebSockErr(
174+
"Failed to connect to websocket - please check your network connection and contact Experiment Controls if this persists.",
175+
);
176+
},
171177
share: true,
172178
retryOnError: true,
173179
});
@@ -182,6 +188,7 @@ export function InstrumentData({ instrumentName }: { instrumentName: string }) {
182188
instName={instName}
183189
runInfoPVs={currentInstrument.runInfoPVs}
184190
/>
191+
{webSockErr && <h1 className={"text-red-600"}>{webSockErr}</h1>}
185192
<div className="flex gap-2 ml-2 md:flex-row flex-col">
186193
<CheckToggle
187194
checked={showHiddenBlocks}

app/components/InstrumentsDisplay.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ export default function InstrumentsDisplay({
6565
},
6666
onOpen: () => {
6767
setInstList([]); // if this is called on a reconnect, clear the instlist so we can re-subscribe to it and get its latest value
68+
setWebSockErr("");
6869
sendJsonMessage(instListSubscription);
6970
// Subscribe to beam current PVs
7071
sendJsonMessage({
@@ -117,13 +118,9 @@ export default function InstrumentsDisplay({
117118
retryOnError: true,
118119
});
119120

120-
if (webSockErr) {
121-
// The instlist isnt available yet so we should tell the user.
122-
return <h1 className={"text-white"}>{webSockErr}</h1>;
123-
}
124-
125121
return (
126122
<div>
123+
{webSockErr && <h1 className={"text-red-600"}>{webSockErr}</h1>}
127124
{sortByGroups &&
128125
Array.from(createInstrumentGroups(instList).entries())
129126
.sort((a, b) => b[1].length - a[1].length) // Sort to display the biggest group first

0 commit comments

Comments
 (0)