Skip to content

Commit 50f6a70

Browse files
committed
fix: add better error handling
1 parent 23ec6dd commit 50f6a70

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

site/src/modules/resources/AgentMetadata.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@ export const AgentMetadata: FC<AgentMetadataProps> = ({
8383
const data = JSON.parse(e.data);
8484
setMetadata(data);
8585
} catch {
86-
displayError("Unable to process newest response from server");
86+
displayError(
87+
"Unable to process newest response from server. The UI may be out of date.",
88+
);
8789
}
8890
});
8991
};

site/src/pages/WorkspacePage/WorkspacePage.test.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,6 @@ describe("WorkspacePage", () => {
9898
.spyOn(API, "deleteWorkspace")
9999
.mockResolvedValueOnce(MockWorkspaceBuild);
100100
await renderWorkspacePage(MockWorkspace);
101-
new MockServerSocket(
102-
`ws://localhost/api/v2/workspaces/${MockWorkspace.id}/watch`,
103-
);
104101

105102
// open the workspace action popover so we have access to all available ctas
106103
const trigger = screen.getByTestId("workspace-options-button");

site/src/pages/WorkspacePage/WorkspacePage.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { useQuery, useQueryClient } from "react-query";
1515
import { useParams } from "react-router-dom";
1616
import { WorkspaceReadyPage } from "./WorkspaceReadyPage";
1717
import { type WorkspacePermissions, workspaceChecks } from "./permissions";
18+
import { displayError } from "components/GlobalSnackbar/utils";
1819

1920
export const WorkspacePage: FC = () => {
2021
const queryClient = useQueryClient();
@@ -84,8 +85,14 @@ export const WorkspacePage: FC = () => {
8485

8586
const socket = watchWorkspace(workspaceId);
8687
socket.addEventListener("message", (event) => {
87-
const newWorkspaceData = JSON.parse(event.data) as Workspace;
88-
void updateWorkspaceData(newWorkspaceData);
88+
try {
89+
const newWorkspaceData = JSON.parse(event.data) as Workspace;
90+
void updateWorkspaceData(newWorkspaceData);
91+
} catch {
92+
displayError(
93+
"Unable to parse latest data from the server. The UI may be out of date.",
94+
);
95+
}
8996
});
9097
socket.addEventListener("error", (event) => {
9198
console.error("Error on getting workspace changes.", event);

0 commit comments

Comments
 (0)