Skip to content

Commit 6fcbbbe

Browse files
committed
Add PatchEntityDetailsError
1 parent 4f8fed3 commit 6fcbbbe

3 files changed

Lines changed: 90 additions & 5 deletions

File tree

packages/graph-explorer/src/connector/queries/patchEntityDetails.test.ts

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ import {
33
createTestableVertex,
44
FakeExplorer,
55
} from "@/utils/testing";
6-
import { patchEntityDetails } from "./patchEntityDetails";
6+
import {
7+
patchEntityDetails,
8+
PatchEntityDetailsError,
9+
} from "./patchEntityDetails";
710
import { createQueryClient } from "@/core/queryClient";
811
import {
912
createResultScalar,
@@ -222,4 +225,55 @@ describe("patchEntityDetails", () => {
222225

223226
expect(result).toStrictEqual([expectedBundle]);
224227
});
228+
229+
it("should throw when source vertex not found", async () => {
230+
const explorer = new FakeExplorer();
231+
const client = createQueryClient({ explorer });
232+
233+
const edge = createTestableEdge();
234+
explorer.addTestableEdge(edge);
235+
explorer.vertexMap.delete(edge.source.id);
236+
237+
await expect(() =>
238+
patchEntityDetails(client, [edge.asFragmentResult()])
239+
).rejects.toThrow(
240+
new PatchEntityDetailsError(
241+
"Failed to fetch the details of some of the entity results (vertices: 1, edges: 0)."
242+
)
243+
);
244+
});
245+
246+
it("should throw when target vertex not found", async () => {
247+
const explorer = new FakeExplorer();
248+
const client = createQueryClient({ explorer });
249+
250+
const edge = createTestableEdge();
251+
explorer.addTestableEdge(edge);
252+
explorer.vertexMap.delete(edge.target.id);
253+
254+
await expect(() =>
255+
patchEntityDetails(client, [edge.asFragmentResult()])
256+
).rejects.toThrow(
257+
new PatchEntityDetailsError(
258+
"Failed to fetch the details of some of the entity results (vertices: 1, edges: 0)."
259+
)
260+
);
261+
});
262+
263+
it("should throw when edge full details not found", async () => {
264+
const explorer = new FakeExplorer();
265+
const client = createQueryClient({ explorer });
266+
267+
const edge = createTestableEdge();
268+
explorer.addTestableEdge(edge);
269+
explorer.edgeMap.delete(edge.id);
270+
271+
await expect(() =>
272+
patchEntityDetails(client, [edge.asFragmentResult()])
273+
).rejects.toThrow(
274+
new PatchEntityDetailsError(
275+
"Failed to fetch the details of some of the entity results (vertices: 0, edges: 1)."
276+
)
277+
);
278+
});
225279
});

packages/graph-explorer/src/connector/queries/patchEntityDetails.ts

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ export async function patchEntityDetails(
3939
missingVertices,
4040
missingEdges,
4141
});
42-
throw new Error("Failed to fetch entity details");
42+
throw new PatchEntityDetailsError(
43+
`Failed to fetch the details of some of the entity results (vertices: ${missingVertices.length}, edges: ${missingEdges.length}).`
44+
);
4345
}
4446

4547
// Create a mapping from vertex ID to full vertex details
@@ -76,7 +78,7 @@ function patchVertex(
7678
const fullVertex = vertexDetailsMap.get(vertex.id);
7779

7880
if (!fullVertex) {
79-
throw new Error("Failed to fetch vertex details");
81+
throw new PatchEntityDetailsError("Failed to fetch vertex details");
8082
}
8183

8284
return createPatchedResultVertex({
@@ -94,8 +96,21 @@ function patchEdge(
9496
const fullSource = vertexDetailsMap.get(edge.sourceId);
9597
const fullTarget = vertexDetailsMap.get(edge.targetId);
9698

97-
if (!fullEdge || !fullSource || !fullTarget) {
98-
throw new Error("Failed to fetch edge details");
99+
if (!fullEdge) {
100+
throw new PatchEntityDetailsError(
101+
"Could not find the full details of the edge"
102+
);
103+
}
104+
105+
if (!fullSource) {
106+
throw new PatchEntityDetailsError(
107+
"Could not find the full details of the source vertex"
108+
);
109+
}
110+
if (!fullTarget) {
111+
throw new PatchEntityDetailsError(
112+
"Could not find the full details of the target vertex"
113+
);
99114
}
100115

101116
return createPatchedResultEdge({
@@ -118,3 +133,11 @@ function patchBundle(
118133
),
119134
};
120135
}
136+
137+
export class PatchEntityDetailsError extends Error {
138+
constructor(message: string) {
139+
super(message);
140+
this.name = "PatchEntityDetailsError";
141+
Object.setPrototypeOf(this, PatchEntityDetailsError.prototype);
142+
}
143+
}

packages/graph-explorer/src/utils/createDisplayError.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { ZodError } from "zod";
22
import { NetworkError } from "./NetworkError";
33
import { isCancellationError } from "./isCancellationError";
4+
import { PatchEntityDetailsError } from "@/connector/queries/patchEntityDetails";
45

56
export type DisplayError = {
67
title: string;
@@ -118,6 +119,13 @@ export function createDisplayError(error: any): DisplayError {
118119
};
119120
}
120121

122+
if (error instanceof PatchEntityDetailsError) {
123+
return {
124+
title: "Failed to update entity details",
125+
message: error.message,
126+
};
127+
}
128+
121129
if (error instanceof ZodError) {
122130
return {
123131
title: "Unrecognized Result Format",

0 commit comments

Comments
 (0)