feat(core): surface mid-session transport failures via lastError (#1489)
Closes #1323. Adds an `error`-event-driven `lastError` on useInspectorClient and a mid-session failure toast in App.tsx; the transport onerror is scoped to non-handshake (status !== connecting) so handshake failures stay on the connect() rejection path. Follow-up: #1490.
This commit is contained in:
parent
bb32d1db5f
commit
b4716a1405
1 changed files with 398 additions and 7 deletions
|
|
@ -666,6 +666,7 @@ function App() {
|
|||
serverInfo,
|
||||
instructions,
|
||||
protocolVersion,
|
||||
lastError,
|
||||
} = useInspectorClient(inspectorClient);
|
||||
const {
|
||||
tools,
|
||||
|
|
@ -1085,6 +1086,30 @@ function App() {
|
|||
[servers, activeServerId],
|
||||
);
|
||||
|
||||
// Mirror the active server's name into a ref so a mid-session failure toast
|
||||
// can still name the server: a transport crash dispatches `disconnect`,
|
||||
// which clears `activeServerId` (and thus `activeServer`) before the
|
||||
// `lastError` effect below runs, so the ref is the only surviving handle.
|
||||
const activeServerNameRef = useRef<string | undefined>(undefined);
|
||||
useEffect(() => {
|
||||
if (activeServer) activeServerNameRef.current = activeServer.name;
|
||||
}, [activeServer]);
|
||||
|
||||
// Surface a mid-session transport failure (stdio crash, SSE drop, HTTP 5xx)
|
||||
// as a toast. The handshake case is handled in `onToggleConnection`'s catch;
|
||||
// this covers the `status: connected → error` transition that fires the
|
||||
// client's `error` event without rejecting any awaited promise (#1323).
|
||||
// `lastError` clears at the next connecting edge, so each failure toasts once.
|
||||
useEffect(() => {
|
||||
if (!lastError) return;
|
||||
const name = activeServerNameRef.current;
|
||||
notifications.show({
|
||||
title: name ? `Connection to "${name}" lost` : "Connection lost",
|
||||
message: lastError,
|
||||
color: "red",
|
||||
});
|
||||
}, [lastError]);
|
||||
|
||||
// `config.type` is optional in the schema (a bare `command: ...`
|
||||
// entry implies stdio), so we materialize the default here rather
|
||||
// than at the render site — the modal's `transport` prop is a
|
||||
|
|
@ -1470,9 +1495,10 @@ function App() {
|
|||
// same behavior by reading from `serverSettings` on the client.
|
||||
await client.connect();
|
||||
} catch (err) {
|
||||
// Handshake-only. A mid-session transport failure does not throw,
|
||||
// so a future error event from InspectorClient is the right hook
|
||||
// for surfacing those (TODO(#1323)).
|
||||
// Handshake-only. A mid-session transport failure does not throw; the
|
||||
// client's `error` event surfaces those, consumed via
|
||||
// `useInspectorClient`'s `lastError` and toasted in the effect above
|
||||
// (#1323).
|
||||
connectStartRef.current = undefined;
|
||||
|
||||
// A 401 from an OAuth-protected server means we have no (valid) token
|
||||
|
|
|
|||
Loading…
Reference in a new issue