Skip to content

Commit

Permalink
Report fetcher submission errors outward
Browse files Browse the repository at this point in the history
  • Loading branch information
brophdawg11 committed Jun 8, 2023
1 parent 2b586c9 commit d849944
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
26 changes: 26 additions & 0 deletions packages/router/__tests__/router-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9034,6 +9034,32 @@ describe("a router", () => {
});
});

it("action fetch with invalid body (json)", async () => {
let t = setup({
routes: [
{
id: "root",
path: "/",
hasErrorBoundary: true,
},
],
});
let A = await t.fetch("/", {
formMethod: "post",
body: "not json",
formEncType: "application/json",
});
expect(A.fetcher).toBe(IDLE_FETCHER);
expect(t.router.state.errors).toEqual({
index: new ErrorResponse(
400,
"Bad Request",
new Error("Unable to encode submission body"),
true
),
});
});

it("handles fetcher errors at contextual route boundaries", async () => {
let t = setup({
routes: [
Expand Down
8 changes: 7 additions & 1 deletion packages/router/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1665,12 +1665,18 @@ export function createRouter(init: RouterInit): Router {
return;
}

let { path, submission } = normalizeNavigateOptions(
let { path, submission, error } = normalizeNavigateOptions(
future.v7_normalizeFormMethod,
true,
normalizedPath,
opts
);

if (error) {
setFetcherError(key, routeId, error);
return;
}

let match = getTargetMatch(matches, path);

pendingPreventScrollReset = (opts && opts.preventScrollReset) === true;
Expand Down

0 comments on commit d849944

Please sign in to comment.