Skip to content

Commit 2208703

Browse files
authoredAug 16, 2023
Add method and URL to aborted query/queryRoute error message (#10793)
1 parent 2709b84 commit 2208703

File tree

4 files changed

+37
-14
lines changed

4 files changed

+37
-14
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@remix-run/router": patch
3+
---
4+
5+
Add method/url to error message on aborted query/queryRoute calls

‎packages/router/__tests__/hash-test.ts

+4
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ describe("a hash history", () => {
6666
});
6767

6868
it("prefixes raw hash values with /", () => {
69+
let spy = jest.spyOn(console, "warn").mockImplementation(() => {});
70+
6971
dom.window.history.replaceState(null, "", "#hello");
7072
history = createHashHistory({ window: dom.window as unknown as Window });
7173
expect(history.location.pathname).toBe("/hello");
@@ -79,6 +81,8 @@ describe("a hash history", () => {
7981

8082
history.push("../relative");
8183
expect(history.location.pathname).toBe("../relative");
84+
85+
spy.mockReset();
8286
});
8387

8488
describe("listen", () => {

‎packages/router/__tests__/router-test.ts

+22-12
Original file line numberDiff line numberDiff line change
@@ -15022,11 +15022,13 @@ describe("a router", () => {
1502215022
let { query } = createStaticHandler([
1502315023
{
1502415024
id: "root",
15025-
path: "/",
15025+
path: "/path",
1502615026
loader: () => dfd.promise,
1502715027
},
1502815028
]);
15029-
let request = createRequest("/", { signal: controller.signal });
15029+
let request = createRequest("/path?key=value", {
15030+
signal: controller.signal,
15031+
});
1503015032
let e;
1503115033
try {
1503215034
let contextPromise = query(request);
@@ -15036,7 +15038,9 @@ describe("a router", () => {
1503615038
} catch (_e) {
1503715039
e = _e;
1503815040
}
15039-
expect(e).toMatchInlineSnapshot(`[Error: query() call aborted]`);
15041+
expect(e).toMatchInlineSnapshot(
15042+
`[Error: query() call aborted: GET http://localhost/path?key=value]`
15043+
);
1504015044
});
1504115045

1504215046
it("should handle aborted submit requests", async () => {
@@ -15045,11 +15049,11 @@ describe("a router", () => {
1504515049
let { query } = createStaticHandler([
1504615050
{
1504715051
id: "root",
15048-
path: "/",
15052+
path: "/path",
1504915053
action: () => dfd.promise,
1505015054
},
1505115055
]);
15052-
let request = createSubmitRequest("/", {
15056+
let request = createSubmitRequest("/path?key=value", {
1505315057
signal: controller.signal,
1505415058
});
1505515059
let e;
@@ -15061,7 +15065,9 @@ describe("a router", () => {
1506115065
} catch (_e) {
1506215066
e = _e;
1506315067
}
15064-
expect(e).toMatchInlineSnapshot(`[Error: query() call aborted]`);
15068+
expect(e).toMatchInlineSnapshot(
15069+
`[Error: query() call aborted: POST http://localhost/path?key=value]`
15070+
);
1506515071
});
1506615072

1506715073
it("should assign signals to requests by default (per the", async () => {
@@ -16327,11 +16333,11 @@ describe("a router", () => {
1632716333
let { queryRoute } = createStaticHandler([
1632816334
{
1632916335
id: "root",
16330-
path: "/",
16336+
path: "/path",
1633116337
loader: () => dfd.promise,
1633216338
},
1633316339
]);
16334-
let request = createRequest("/", {
16340+
let request = createRequest("/path?key=value", {
1633516341
signal: controller.signal,
1633616342
});
1633716343
let e;
@@ -16343,7 +16349,9 @@ describe("a router", () => {
1634316349
} catch (_e) {
1634416350
e = _e;
1634516351
}
16346-
expect(e).toMatchInlineSnapshot(`[Error: queryRoute() call aborted]`);
16352+
expect(e).toMatchInlineSnapshot(
16353+
`[Error: queryRoute() call aborted: GET http://localhost/path?key=value]`
16354+
);
1634716355
});
1634816356

1634916357
it("should handle aborted submit requests", async () => {
@@ -16352,11 +16360,11 @@ describe("a router", () => {
1635216360
let { queryRoute } = createStaticHandler([
1635316361
{
1635416362
id: "root",
16355-
path: "/",
16363+
path: "/path",
1635616364
action: () => dfd.promise,
1635716365
},
1635816366
]);
16359-
let request = createSubmitRequest("/", {
16367+
let request = createSubmitRequest("/path?key=value", {
1636016368
signal: controller.signal,
1636116369
});
1636216370
let e;
@@ -16368,7 +16376,9 @@ describe("a router", () => {
1636816376
} catch (_e) {
1636916377
e = _e;
1637016378
}
16371-
expect(e).toMatchInlineSnapshot(`[Error: queryRoute() call aborted]`);
16379+
expect(e).toMatchInlineSnapshot(
16380+
`[Error: queryRoute() call aborted: POST http://localhost/path?key=value]`
16381+
);
1637216382
});
1637316383

1637416384
it("should assign signals to requests by default (per the spec)", async () => {

‎packages/router/router.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -2850,7 +2850,9 @@ export function createStaticHandler(
28502850

28512851
if (request.signal.aborted) {
28522852
let method = isRouteRequest ? "queryRoute" : "query";
2853-
throw new Error(`${method}() call aborted`);
2853+
throw new Error(
2854+
`${method}() call aborted: ${request.method} ${request.url}`
2855+
);
28542856
}
28552857
}
28562858

@@ -3018,7 +3020,9 @@ export function createStaticHandler(
30183020

30193021
if (request.signal.aborted) {
30203022
let method = isRouteRequest ? "queryRoute" : "query";
3021-
throw new Error(`${method}() call aborted`);
3023+
throw new Error(
3024+
`${method}() call aborted: ${request.method} ${request.url}`
3025+
);
30223026
}
30233027

30243028
// Process and commit output from loaders

0 commit comments

Comments
 (0)
Please sign in to comment.