File tree Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Original file line number Diff line number Diff line change @@ -9034,6 +9034,32 @@ describe("a router", () => {
90349034 });
90359035 });
90369036
9037+ it("action fetch with invalid body (json)", async () => {
9038+ let t = setup({
9039+ routes: [
9040+ {
9041+ id: "root",
9042+ path: "/",
9043+ hasErrorBoundary: true,
9044+ },
9045+ ],
9046+ });
9047+ let A = await t.fetch("/", {
9048+ formMethod: "post",
9049+ body: "not json",
9050+ formEncType: "application/json",
9051+ });
9052+ expect(A.fetcher).toBe(IDLE_FETCHER);
9053+ expect(t.router.state.errors).toEqual({
9054+ index: new ErrorResponse(
9055+ 400,
9056+ "Bad Request",
9057+ new Error("Unable to encode submission body"),
9058+ true
9059+ ),
9060+ });
9061+ });
9062+
90379063 it("handles fetcher errors at contextual route boundaries", async () => {
90389064 let t = setup({
90399065 routes: [
Original file line number Diff line number Diff line change @@ -1665,12 +1665,18 @@ export function createRouter(init: RouterInit): Router {
16651665 return ;
16661666 }
16671667
1668- let { path, submission } = normalizeNavigateOptions (
1668+ let { path, submission, error } = normalizeNavigateOptions (
16691669 future . v7_normalizeFormMethod ,
16701670 true ,
16711671 normalizedPath ,
16721672 opts
16731673 ) ;
1674+
1675+ if ( error ) {
1676+ setFetcherError ( key , routeId , error ) ;
1677+ return ;
1678+ }
1679+
16741680 let match = getTargetMatch ( matches , path ) ;
16751681
16761682 pendingPreventScrollReset = ( opts && opts . preventScrollReset ) === true ;
You can’t perform that action at this time.
0 commit comments