Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add method and URL to aborted query/queryRoute error message #10793

Merged
merged 1 commit into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/aborted-query-error-message.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@remix-run/router": patch
---

Add method/url to error message on aborted query/queryRoute calls
4 changes: 4 additions & 0 deletions packages/router/__tests__/hash-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ describe("a hash history", () => {
});

it("prefixes raw hash values with /", () => {
let spy = jest.spyOn(console, "warn").mockImplementation(() => {});
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clear up some unintended output during unit tests


dom.window.history.replaceState(null, "", "#hello");
history = createHashHistory({ window: dom.window as unknown as Window });
expect(history.location.pathname).toBe("/hello");
Expand All @@ -79,6 +81,8 @@ describe("a hash history", () => {

history.push("../relative");
expect(history.location.pathname).toBe("../relative");

spy.mockReset();
});

describe("listen", () => {
Expand Down
34 changes: 22 additions & 12 deletions packages/router/__tests__/router-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 () => {
Expand All @@ -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;
Expand All @@ -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 () => {
Expand Down Expand Up @@ -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;
Expand All @@ -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 () => {
Expand All @@ -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;
Expand All @@ -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 () => {
Expand Down
8 changes: 6 additions & 2 deletions packages/router/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`
);
}
}

Expand Down Expand Up @@ -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
Expand Down