diff --git a/.changeset/aborted-query-error-message.md b/.changeset/aborted-query-error-message.md new file mode 100644 index 0000000000..4aabb4e435 --- /dev/null +++ b/.changeset/aborted-query-error-message.md @@ -0,0 +1,5 @@ +--- +"@remix-run/router": patch +--- + +Add method/url to error message on aborted query/queryRoute calls diff --git a/packages/router/__tests__/hash-test.ts b/packages/router/__tests__/hash-test.ts index 76d60255a0..60bae0b926 100644 --- a/packages/router/__tests__/hash-test.ts +++ b/packages/router/__tests__/hash-test.ts @@ -66,6 +66,8 @@ describe("a hash history", () => { }); it("prefixes raw hash values with /", () => { + let spy = jest.spyOn(console, "warn").mockImplementation(() => {}); + dom.window.history.replaceState(null, "", "#hello"); history = createHashHistory({ window: dom.window as unknown as Window }); expect(history.location.pathname).toBe("/hello"); @@ -79,6 +81,8 @@ describe("a hash history", () => { history.push("../relative"); expect(history.location.pathname).toBe("../relative"); + + spy.mockReset(); }); describe("listen", () => { diff --git a/packages/router/__tests__/router-test.ts b/packages/router/__tests__/router-test.ts index ed681a554b..6c58ad9e90 100644 --- a/packages/router/__tests__/router-test.ts +++ b/packages/router/__tests__/router-test.ts @@ -15022,11 +15022,13 @@ describe("a router", () => { let { query } = createStaticHandler([ { id: "root", - path: "/", + path: "/path", loader: () => dfd.promise, }, ]); - let request = createRequest("/", { signal: controller.signal }); + let request = createRequest("/path?key=value", { + signal: controller.signal, + }); let e; try { let contextPromise = query(request); @@ -15036,7 +15038,9 @@ describe("a router", () => { } catch (_e) { e = _e; } - expect(e).toMatchInlineSnapshot(`[Error: query() call aborted]`); + expect(e).toMatchInlineSnapshot( + `[Error: query() call aborted: GET http://localhost/path?key=value]` + ); }); it("should handle aborted submit requests", async () => { @@ -15045,11 +15049,11 @@ describe("a router", () => { let { query } = createStaticHandler([ { id: "root", - path: "/", + path: "/path", action: () => dfd.promise, }, ]); - let request = createSubmitRequest("/", { + let request = createSubmitRequest("/path?key=value", { signal: controller.signal, }); let e; @@ -15061,7 +15065,9 @@ describe("a router", () => { } catch (_e) { e = _e; } - expect(e).toMatchInlineSnapshot(`[Error: query() call aborted]`); + expect(e).toMatchInlineSnapshot( + `[Error: query() call aborted: POST http://localhost/path?key=value]` + ); }); it("should assign signals to requests by default (per the", async () => { @@ -16327,11 +16333,11 @@ describe("a router", () => { let { queryRoute } = createStaticHandler([ { id: "root", - path: "/", + path: "/path", loader: () => dfd.promise, }, ]); - let request = createRequest("/", { + let request = createRequest("/path?key=value", { signal: controller.signal, }); let e; @@ -16343,7 +16349,9 @@ describe("a router", () => { } catch (_e) { e = _e; } - expect(e).toMatchInlineSnapshot(`[Error: queryRoute() call aborted]`); + expect(e).toMatchInlineSnapshot( + `[Error: queryRoute() call aborted: GET http://localhost/path?key=value]` + ); }); it("should handle aborted submit requests", async () => { @@ -16352,11 +16360,11 @@ describe("a router", () => { let { queryRoute } = createStaticHandler([ { id: "root", - path: "/", + path: "/path", action: () => dfd.promise, }, ]); - let request = createSubmitRequest("/", { + let request = createSubmitRequest("/path?key=value", { signal: controller.signal, }); let e; @@ -16368,7 +16376,9 @@ describe("a router", () => { } catch (_e) { e = _e; } - expect(e).toMatchInlineSnapshot(`[Error: queryRoute() call aborted]`); + expect(e).toMatchInlineSnapshot( + `[Error: queryRoute() call aborted: POST http://localhost/path?key=value]` + ); }); it("should assign signals to requests by default (per the spec)", async () => { diff --git a/packages/router/router.ts b/packages/router/router.ts index 1fabd4bc5b..c5101bcb9e 100644 --- a/packages/router/router.ts +++ b/packages/router/router.ts @@ -2850,7 +2850,9 @@ export function createStaticHandler( if (request.signal.aborted) { let method = isRouteRequest ? "queryRoute" : "query"; - throw new Error(`${method}() call aborted`); + throw new Error( + `${method}() call aborted: ${request.method} ${request.url}` + ); } } @@ -3018,7 +3020,9 @@ export function createStaticHandler( if (request.signal.aborted) { let method = isRouteRequest ? "queryRoute" : "query"; - throw new Error(`${method}() call aborted`); + throw new Error( + `${method}() call aborted: ${request.method} ${request.url}` + ); } // Process and commit output from loaders